htaccess RewriteRule 500 error

2019-09-02 20:42发布

Let's say I had this:

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

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

1条回答
贼婆χ
2楼-- · 2019-09-02 21:20

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]

Full .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]
查看更多
登录 后发表回答