Ivar
Ivar

Reputation: 4392

htaccess: Why doesn't this work?

I get a 404 error page when I try the following rule in htaccess:

RewriteRule ^Test\?service=(.*) test.php?foo=$1 [NC,L]

How come?

I know it's preferable to use something like ^Test/(.*) test.php?foo=$1 [NC,L] instead, but in this case I'd rather like it the way I stated.

Thank you in advance.

Upvotes: 1

Views: 116

Answers (1)

Gumbo
Gumbo

Reputation: 655239

RewriteRule does only check the URL path. But the query (the part from the first ? up to the first #) is not part of the URL path. That can only be checked with the RewriteCond directive:

RewriteCond %{QUERY_STRING} ^service=(.*)
RewriteRule ^Test$ test.php?foo=%1 [NC,L]

Upvotes: 1

Related Questions