htaccess的重写规则500错误重写、规则、错误、htaccess

2023-09-02 01:06:49 作者:愚剧

比方说,我有这样的:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

页/ 及以后的(页/错误/ 等)给了我一个500错误。

page/ and onwards (page/error/ etc) gives me a 500 error.

推荐答案

您可以使用此规则,使最后一个斜线和其他URI组件可选:

You can use this rule to make last slash and other URI components optional:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

完整的.htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
 
精彩推荐
图片推荐