Reputation: 1111
I keep seeing this error in my apache log when someone visits the shop page on my site, I have tried removing my htaccess and using .php?s=$var and I still get the same error so I think its something to do with the apache config files and not anything to do with the htaccess file, here it is anyway
htaccess:
RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} //
RewriteRule ^(.*)$ /$1 [L,R=301]
RewriteRule ^home/?$ home.php [NC]
RewriteCond %{THE_REQUEST} /shop\?c=([^&\s]+)&s=([^&\s]+)&s2=([^&\s]+)&b=([^&\s]+) [NC]
RewriteRule ^ shop/%1/%2/%3/%4? [L,R=302,NE]
RewriteRule ^shop/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ shop.php?c=$1&s=$2&s2=$3&b=$4 [L,QSA,B]
RewriteRule ^shop/([^/]+)/([^/]+)/([^/]+)/?$ shop.php?c=$1&s=$2&s2=$3 [L,QSA,B]
RewriteRule ^shop/([^/]+)/([^/]+)/?$ shop.php?c=$1&s=$2 [L,QSA,B]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
SSL apache conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>
HTTP apache conf:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/example.com">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Upvotes: 0
Views: 1371
Reputation: 45829
There's nothing in the server config files you've posted that would result in a rewrite loop - there are no rewrites in your server config.
I have tried removing my htaccess and using
.php?s=$var
and I still get the same error
That is puzzling. Do you have any other .htaccess
files in subdirectories? Without any .htaccess
files and with the server config you've posted it would seem to be impossible to get a rewrite loop - since you would have no rewrites at all!
However, your last rule block that appends the .php
extension could result in a rewrite loop under certain conditions. This needs to be corrected. You currently have:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L]
The problem with this is that the 2nd condition that checks to see that <filename>.php
exists, is not necessarily performing the same file check that the following RewriteRule
would rewrite to. eg. Request /foo/bar
, where /foo.php
exists, would result in a rewrite loop.
To resolve this issue, you would need to change the 2nd condition to something like the following instead:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
See my answer to the following ServerFault question that explains this in more detail:
So, the complete rule becomes:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]
You should also ensure that MultiViews is disabled (if not already), since your URLs map directly to files less the .php
file extension (otherwise mod_negotiation will rewrite the URL - before mod_rewrite - and you will lose the URL parameters). At the top of your .htaccess
file include:
Options -MultiViews
Upvotes: 0