网址具有两次文件名时出现内部服务器错误

时间:2019-06-08 07:35:18

标签: .htaccess

当我从url写入两次文件名时,出现500 Internal Server Error。

我将以下RewriteRule用于用户个人资料网址:

RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,QSA,NC]  
RewriteRule ^profile/(followers|friends|saved|stories)/([^/]+)/?$ $1.php?username=$2 [L,QSA,NC]

规则在此链接下正常工作

https://www.thewebsiteurl.com/profile/username

但是如果我这样写了两次文件名

https://www.thewebsiteurl.com/profile/profile/username

然后我收到500 Internal Server Error。

这里是否有解决此问题的答案?

这是我的全部HTACCESS代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /

ErrorDocument 404 https://www.websiteurl.com/sources/not-found.php          
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,QSA,NC]  
RewriteRule ^profile/(followers|friends|saved|stories)/([^/]+)/?$ $1.php?username=$2 [L,QSA,NC]    


RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L] 


<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin '*'
</IfModule>

1 个答案:

答案 0 :(得分:1)

虽然我在某些Web服务器中发现%{REQUEST_FILENAME}.php由于文件名解析问题而无法正常工作,但规则似乎还可以。

您可以尝试将该规则更改为此吗?

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]