.htaccess获取变量重定向导致500内部服务器错误



我已经通读了与此主题相关的其他帖子,但仍然没有找到我的解决方案。

我的.htaccess如下:

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]
ErrorDocument 404 https://website.com/page/404
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^ ]+).php
RewriteRule ^/?(.*).php$ /$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index /$1 [R=301,L]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]

每当我导航到https://website.com/page/profile/name/我收到一个500内部服务器错误。

其他条件似乎运行正常,但这一个条件尤其不正常。

这不能工作:

RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]

您必须使用以下内容定义变量:(.*(

RewriteEngine on
RewriteBase "/"
RewriteCond %{HTTP_Host}          "!^$" [NC]
RewriteRule "^profile/(.*).php$"   "profile.php?username=$1"       [NC,L,QSA]

之后,您可以检查regex。

最新更新