How to use .htaccess for file rewriting .php on GCP? - php

I have a .htaccess file which is rewriting all of my urls from path/to/file.php to just path/to/file.
I had this working locally on WAMP, and it also worked on a domain hosted by blacknight.
However, we are moving to Google Cloud Platform using Debian 9, and it does not work here at all. If I do not include the .php extension I will get a 404 error.
Below is my full .htaccess file:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^post/([^\/]+)/?$ post.php?url=$1 [L,NC,QSA]
RewriteRule ^payment/([^\/]+)/?$ payment.php?sub=$1 [L,NC,QSA]
RewriteRule ^player/([^\/]+)/?$ player.php?id=$1 [L,NC,QSA]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 week"
ExpiresByType image/jpeg "access 1 week"
ExpiresByType image/gif "access 1 week"
ExpiresByType image/png "access 1 week"
ExpiresByType text/css "access 1 hour"
ExpiresByType text/x-javascript "access 1 hour"
</IfModule>
<IfModule mod_headers.c>
Header set Connection keep-alive
<filesmatch "\.(ico|gif|jpg|jpeg|png)$">
Header set Cache-Control "max-age=604800, public"
</filesmatch>
<filesmatch "\.(css)$">
Header set Cache-Control "max-age=3600, private"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=3600, private"
</filesmatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=0, private, must-revalidate"
</filesMatch>
</IfModule>
What can I do to resolve this or is there another way of rewriting URLs in Google Cloud Platform?

If your Apache server is enabled you should check if the AllowOverride directive is enabled as well (set to "All" or allowing specific options). Otherwise Apache will not consider the directives that you put there.
This should usually be placed in your Virtual server config file or the main one.
Here is an example:
<Directory "/path/from/where/you/serve/files">
AllowOverride All
</Directory>
More info:
https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

Related

Wordpress install on add-on site redirecting to main site

My main website is:
http://sandybeachit.co.uk
I have a wordpress site setup at my addon-domain:
[http://imadeitviral.com][1]
The wordpress site is in:
/hosting/imadeitviral
The above address can be found here on the primary site under sandybeachit.co.uk/hosting/imadeitviral/
I have got the site url and home set to "http:// imadeitviral.com" (without the space between "http:// and madeitviral.com"
But when you go imadeitviral.com the site attempts to load my primary site at sandybeachit.co.uk except the site does not load correctly, you can try it and your see what i mean.
If i set the wordpress site url and home to pointing to "sandybeachit.co.uk/hosting/imadeitviral" the site will load fine, so i know i have got something wrong, but i can not figure out what.
I have tried removing the .htaccess file in my main domain and editing it so i an sure its not that is the problem as well as the .htaccess file in the wordpress folder.
I did the install via Site Software Softaculous Apps Installer
Can i get some pointers as to what i have done wrong or missed ?
Thanks
HTACCESS FILE IN WORDPRESS DIRECTORY:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /hosting/imadeitviral/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /hosting/imadeitviral/index.php [L]
</IfModule>
# END WordPress
HTACCESS FILE IN MAIN DIRECTORY:
RewriteCond %{HTTP_HOST} ^(www\.)?imadeitviral\.com
RewriteRule .* - [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ /$0/ [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#RULES ADDED AFTER 14TH JANUARY 2017
# Set Timezone
<IfModule !fcgid_module>
php_value date.timezone "Europe/London"
</IfModule>
# Disable directory browsing
Options All -Indexes
### Security - Disable HTTP Track and Trace
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>
#DENY ACCESS - START
<FilesMatch "config.php|\.tpl$">
Order allow,deny
Deny from all
</FilesMatch>
#DENY ACCESS - END
# One year for image files
<filesMatch ".(jpg|jpeg|png|gif|ico)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
# One month for css and js
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT"
Header unset ETag
FileETag None
</FilesMatch>
# BEGIN EXPIRES
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
# GZIP BEGIN - COMPRESS - .CSS .JS .HTML .XHTML .PHP .TXT
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript
</ifmodule>
#End Gzip
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
#The following line also enables compression by file content type, for the following list of Content-Type:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<ifModule mod_headers.c>
Header unset Vary
Header set Vary "Accept-Encoding, X-HTTP-Method-Override, X-Forwarded-For, Remote-Address, X-Real-IP, X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port, X-Forwarded-Server"
</ifModule>
After a little more testing:
What i am finding is if i goto:
imadeitviral.com/
The site loads
As soon as i go into:
imadeitviral.com/wp-admin
after a short while the site times out to a 404 with the message:
"Not Found
The requested URL /wp-admin/plugins.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

HTTP to HTTPS Redirection Error on Wordpress

I'm trying to move my wordpress blog to https, however I tried many things but all of them give me a redirect loop error.
This is my current htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
# BEGIN EXPIRES
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
<FilesMatch "\.(ico|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "private"
</FilesMatch>
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</FilesMatch>
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
And i added this to wp-config.php:
/* SSL Settings */
define('FORCE_SSL_ADMIN', true);
/* Turn HTTPS 'on' if HTTP_X_FORWARDED_PROTO matches 'https' */
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
This are the different variants I tried to redirect to https:
Variant 1:
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Variant 2
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://example.com/$1 [R,L]
Variant 3
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
All of them give me a redirect loop, any idea how I can fix this?
Thanks
Just fixed it with Really Simple SSL plugin for wordpress, If anyone is having this problem I recommend you try it.
You shouldn't need to use a plugin nor touch the .htaccess of your WordPress installation to get it to work on HTTPS. Change the Site and WordPress URLs in the admin area within Settings > General.
Here is a useful guide on how to change the site URLs.
You can also just force it within the admin area only by putting the following in your config.php file (in the WordPress root), although having it everywhere is best.
define('FORCE_SSL_ADMIN', true);
Generally though, I'd avoid using a plugin for something like this which can be done natively and easily too.

Rewrite php url variables with mod_rewrite htaccess [duplicate]

This question already has answers here:
mod_rewrite not working htaccess
(3 answers)
Closed 6 years ago.
I'm still working my way round htaccess and would like some input on whether my code is correct or needs some work. Also I know there are tonnes of questions like this but still can't figure it out, how do I rewrite the URL days/content.php?day=mon to days/mon or days/content/mon? Thanks!
#---------------------------------------------------------
#rewrite engine + rewritecond
#---------------------------------------------------------
<IfModule mod_rewrite.c>
# enable the rewrite engine
Options +FollowSymlinks
RewriteEngine On
# Set your root directory
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
# remove index and reference the directory
RewriteRule (.*)/index$ $1/ [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
#prevent hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?dundaah.com [NC]
RewriteRule \.(jpe?g|png|gif|bmp|css|js|php|xml)$ - [NC,F,L]
#deny access to hidden files and directories
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
#---------------------------------------------------------
#compress text files
#---------------------------------------------------------
<IfModule mod_deflate.c>
# Force compression for mangled headers.
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
#---------------------------------------------------------
#compress files with mod_gzip
#---------------------------------------------------------
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
#---------------------------------------------------------
#set expires headers cache control
#---------------------------------------------------------
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 week"
#CSS
ExpiresByType text/css "access plus 1 week"
#Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
#Favicon (cannot be renamed!)
ExpiresByType image/x-icon "access plus 1 week"
#HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 week"
#HTML
ExpiresByType text/html "access plus 0 seconds"
#JavaScript
ExpiresByType application/javascript "access plus 1 week"
#Manifest files
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
#Media
ExpiresByType audio/ogg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType video/mp4 "access plus 1 week"
ExpiresByType video/ogg "access plus 1 week"
ExpiresByType video/webm "access plus 1 week"
#Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
#Web fonts
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
#---------------------------------------------------------
#cache files
#---------------------------------------------------------
<ifModule mod_headers.c>
<filesMatch ".(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch ".(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch ".(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch ".(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
#to disable for certain file type
<FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</ifModule>
#---------------------------------------------------------
#turn e-tags off
#---------------------------------------------------------
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
#---------------------------------------------------------
#disable dir browsing + script execution
#---------------------------------------------------------
Options -Indexes -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
#---------------------------------------------------------
#block access to your .htaccess file + more
#---------------------------------------------------------
<Files .htaccess>
order allow,deny
deny from all
</Files>
#---------------------------------------------------------
#create custom error pages
#---------------------------------------------------------
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
#---------------------------------------------------------
#display no php errors to user
#---------------------------------------------------------
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
#---------------------------------------------------------
# log php errors to file
#---------------------------------------------------------
php_flag log_errors on
#php_value error_log /location/to/php_error.log
If you're looking to rewrite the URL days/content.php?day=mon to days/mon, consider the following rewriting rules:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/days/content.php
RewriteCond %{QUERY_STRING} ^day=([a-zA-Z]+)$
RewriteRule ^(.*)$ /days/%1? [R,L]
or if you're looking to rewrite it to days/content/mon, consider this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/days/content.php
RewriteCond %{QUERY_STRING} ^day=([a-zA-Z]+)$
RewriteRule ^(.*)$ /days/content/%1? [R,L]
Hope it helps!
All you need to use is this:
RewriteEngine On
RewriteRule ^days/([^/]*)$ /days/content.php?day=$1 [L]
It will leave you with the URL: www.example.com/days/mon.
Make sure you clear your cache before testing it.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^days\/(.+)$ days/content.php?day=$1 [NC,L]
will redirect from days/mon to days/content.php?day=mon.
If you are getting a not found error, it may be because of the RewriteBase /. By default, .htaccess urls are relative to the directory it is in. By setting the base to /, the urls then become relative to root instead.
For the example below, I have removed RewriteBase:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# This shouldn't be required, as it defaults to the directory the .htaccess is in
# RewriteBase /
# rewrite days/[day] into days/content.php?day=[day]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^days\/(.+)$ days/content.php?day=$1 [NC,L]
...
</IfModule>

leverage browser caching .htaccess not working

I am using laravel 5, for speed I test in google speed insight, its showing leverage browser caching
to solve that I have used following .htaccess code but non of them are working
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]
</IfModule>
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]
# Serve gzip compressed JS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header append Content-Encoding gzip
# Force proxies to cache gzipped &
# non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# Media: images, video, audio
ExpiresByType assets/images "access plus 1 month"
# CSS and JavaScript
ExpiresByType assets/css "access plus 1 month"
ExpiresByType assets/js "access plus 1 month"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
Second code that I used in .htaccess is this one
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 year"
ExpiresByType text/html "access plus 1 second"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
</IfModule>
I also tried this one code in .htaccess to make it work, but this one is also not working
<IfModule mod_expires.c>
# Set Cache-Control and Expires headers
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "max-age=2592000, public"
Header set Expires "1 day"
</filesMatch>
<filesMatch "\\.(css|css.gz)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\\.(js|js.gz)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm)$">
Header set Cache-Control "max-age=7200, public, must-revalidate"
</filesMatch>
</IfModule>
I have used all above code but I got same result every time
should fix: Leverage browser caching
on most of the anaylser.
is anything I am missing in this
If You are in ubuntu try this
sudo a2enmod expires
sudo systemctl restart apache2
Check that modules are enable in server.
If modules are not enabled than code will not work.

I receive 404 error only when submit secured url as value

I receive 404 server error when submit https://example.com/.../image.png as value from a html form. When submit the same url with http:// (not secured url) everything works fine.
Is there any restriction to submit https:// urls as value of a form field?
My .htaccess file:
redirect 301 /category/новини/ http://barimax.bg/новини/
ErrorDocument 404 /index.php?id=404
# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType image/gif "access plus 2678400 seconds"
ExpiresByType image/jpeg "access plus 2678400 seconds"
ExpiresByType image/png "access plus 2678400 seconds"
ExpiresByType text/css "access plus 518400 seconds"
ExpiresByType text/javascript "access plus 2678400 seconds"
ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>
# Cache Headers
<ifmodule mod_headers.c>
# Cache specified files for 31 days
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
# Cache HTML files for a couple hours
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
# Cache PDFs for a day
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
# Cache Javascripts for 31 days
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</ifmodule>
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !ckfinder.html
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ https://barimax.bg/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#RewriteCond %{HTTP_HOST} ^barimax.bg [NC,OR]
#RewriteCond %{HTTP_HOST} ^www.barimax.bg .com [NC]
#RewriteRule ^(.*)$ https://www.barimax.bg/$1 [L,R=301,NC]
AuthName "www"
AuthUserFile "/home/barimax/.htpasswds/public_html/passwd"
AddHandler application/x-httpd-php54 .php54 .php

Categories