[当有人访问我网站上的商店页面时,我一直在我的apache日志中看到此错误,我尝试删除htaccess并使用.php?s = $ var,但我仍然遇到相同的错误,所以我认为这是可以做的与apache配置文件,与htaccess文件无关,无论如何,这里是
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>
您发布的服务器配置文件中没有任何东西会导致重写循环-这里没有重写。
我尝试删除htaccess并使用
.php?s=$var
,但仍然收到相同的错误
令人费解。子目录中是否还有其他.htaccess
文件?没有任何.htaccess
文件并且没有发布您的服务器配置,似乎就不可能获得重写循环-因为您根本没有重写!
但是,在某些情况下,最后一个附加了.php
扩展名的规则块可能导致重写循环。这需要纠正。您当前有:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L]
这样做的问题是,检查第二个条件以检查<filename>.php
是否存在,并不一定要执行相同的文件检查,以使后续的RewriteRule
重写。例如。存在/foo/bar
的请求/foo.php
将导致重写循环。
要解决此问题,您需要将第二个条件改为如下所示:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
请参阅下面的ServerFault问题的my answer,该问题将对此进行更详细的说明:
您还应确保已禁用MultiViews(如果尚未禁用),因为您的URL直接映射到文件扩展名小于.php
文件扩展名的文件(否则,在mod_rewrite之前,mod_negotiation将重写URL,并且您将丢失URL参数)。在.htaccess
文件的顶部包括:
Options -MultiViews