开发者

Rewrite rule not working

I want to write a rule that redirects all URLs of a certain pattern to a PHP file. Exception: the control/ directory where the CMS resides.

Why does

RewriteCond  %{REQUEST_URI} ^/([^control]+)/([^/]+)$   
RewriteRule .* /pages/index.php?language=%1&page=%2&%{QUERY_STRING} [L]

not work for

domain.com/deutsch/start

(it throws a 404), while

Rewr开发者_开发百科iteCond  %{REQUEST_URI} ^/([^control]+)/([^/]+)/debug$   
RewriteRule .* /pages/index.php?language=%1&page=%2&page_debug=yes&%{QUERY_STRING} [L]

works for

domain.com/deutsch/start/debug

?


You need to use two conditions:

RewriteCond %{REQUEST_URI} !^/control/
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)$
RewriteRule .* /pages/index.php?language=%1&page=%2&%{QUERY_STRING} [L]

But you should use your pattern directly in the RewriteRule directive if possible:

RewriteCond $1 !=control
RewriteRule ^([^/]+)/([^/]+)$ /pages/index.php?language=$1&page=$2&%{QUERY_STRING} [L]

Another hint is to use the QSA flag instead of appending the query explicitly:

RewriteCond $1 !=control
RewriteRule ^([^/]+)/([^/]+)$ /pages/index.php?language=$1&page=$2 [L,QSA]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜