Pekka
Pekka

Reputation: 449385

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

RewriteCond  %{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

?

Upvotes: 0

Views: 351

Answers (1)

Gumbo
Gumbo

Reputation: 655129

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]

Upvotes: 1

Related Questions