After having read a lot of posts on the topic of URL rewriting, I still remain stuck with 404 status errors.

My goal:

A 'static' rewrite of URLs, as follows (user clicks or enters the one URL/script, but internally the other one is being executed - the parameters are also 'static', hence I think I cannot use any kind of pattern (*.) and $1 in the rule...:

  • domain.tld/en/abc.php?foo to domain.tld/en/xyz.php?bar (1st level)
  • domain.tld/en/abc.php?foo&blabla to domain.tld/en/xyz.php?bar&otherstring (2nd level)

Additional Info:

  • Directory 'en' exists.
  • Script abc.php does not exist
  • Script xyz.php exists and works fine with the given static parameter(s)

My .htaccess:

Options +FollowSymLinks 
RewriteEngine On
RewriteRule ^en/abc\.php\?foo&blabla$ /en/xyz.php?bar&otherstring [NC,L]
RewriteRule ^en/abc\.php\?foo$ /en/xyz.php?bar [NC,L]

I already get a 404 error on this simpler last rule. I don't have access to the rewritelog.

  • Please do not cross-post questions to other Stack Exchange sites: stackoverflow.com/questions/25114786/…
    – dan
    Commented Aug 5, 2014 at 7:36
  • Sorry. I only realised later that this webmasters' site may be better suited.
    – LarryG001
    Commented Aug 5, 2014 at 8:51
  • NBD, it is better suited here because it's not about programming and will likely get closed there anyway. That's just to let others know to check the answers there too (and a reminder for them). Welcome to the site by the way.
    – dan
    Commented Aug 5, 2014 at 8:59

1 Answer 1


You can't check for the query string using the RewriteRule pattern (the query string is stripped before pattern matching, as is the hostname, etc). So, the rules you stated above simply won't match and you'll get a 404. However, you can use the RewriteCond directive to check the query string:

For example:

domain.tld/en/abc.php?foo to domain.tld/en/xyz.php?bar

RewriteCond %{QUERY_STRING} =foo
RewriteRule ^en/abc\.php$ /en/xyz.php?bar [L]

Note that this matches the exact query string "foo". I've removed the NC flag, unless you specifically need a case-insensitive match?

  • OK,thx. So am I right when for 2 params, it would be: RewriteCond %{HTTP_QUERY_STRING}=foo&blabla Rewriterule ^en/abc\.php$ /en/xyz.php?bar&otherstring [L]
    – LarryG001
    Commented Aug 5, 2014 at 8:54
  • Yes, that looks OK. Note there is a space before the =. (The = operator makes an exact string match as opposed to a regular expression.)
    – MrWhite
    Commented Aug 5, 2014 at 8:57
  • I just tested your solution, but adding the RewriteCond to my .htaccess produced a 500 Internal Server Error. When removing the RewriteCond, the 500 error is gone. ??
    – LarryG001
    Commented Aug 5, 2014 at 9:02
  • Sorry, it should be QUERY_STRING, not HTTP_QUERY_STRING as in my original post, just updated it.
    – MrWhite
    Commented Aug 5, 2014 at 9:03
  • 1
    Yes !!!!! Everything works fine according to your solution!!! And you saved my day (and night) !
    – LarryG001
    Commented Aug 5, 2014 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.