Mobile app version of vmapp.org
Login or Join
Rivera981

: Statically mapping a PHP script to another script using an .htaccess file results in 404 errors After having read a lot of posts on the topic of URL rewriting, I still remain stuck with 404

@Rivera981

Posted in: #Apache #Htaccess #Php #UrlRewriting

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 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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Rivera981

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

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?

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme