URL rewrite : internal server error

北慕城南 提交于 2019-12-11 09:49:21

问题


I have a little problem on Apache's rewrite rules

Here's my rules

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteRule query/(.*) /php/query.php?name=$1 [L]
RewriteRule page/(.*) /php/page.php?page=$1 [L]

It works perfectly. But when I try to add the following rule to rewrite URL that not matches the two previous rules

RewriteRule .* /php/page.php?page=home

The server responds "Internal server error". Why ?


回答1:


You can use RewriteLog to see what happends, but even with a [L] you can be sure a rewrited url is always re-checked on the set of rules (this is call internal redirect).

So add some RewriteCond before this final catch-all, or prevent it to be running on internal redirects, this way:

RewriteCond %{ENV:REDIRECT_STATUS} ^$

You could also add the [NS] or [nosubreq] tag on your final catch-all, which does the same.

But preventing your rule on internal redirection also means it will never be applied after any previous rule, and one day you might want it. So be careful with next rules.




回答2:


Thanks !

Finally, here's my solution :

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteRule query/(.*) /php/query.php?name=$1 [L]
RewriteRule page/(.*) /php/page.php?page=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ page/home [L,R]
RewriteRule ^$ page/home [NS,R]


来源:https://stackoverflow.com/questions/19809278/url-rewrite-internal-server-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!