比方说,我有这样的:
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]