Mobile app version of vmapp.org
Login or Join
Martha676

: Query string parameters with mod_rewrite RewriteEngine On RewriteRule ^detail.html?id=([0-9]+)-page=([0-9]+)$ detail.php?id=&page= I rewrite URL detail.php?id=1&page=1 to detail.html?id=1&page=1.

@Martha676

Posted in: #Htaccess

RewriteEngine On
RewriteRule ^detail.html?id=([0-9]+)-page=([0-9]+)$ detail.php?id=&page=


I rewrite URL detail.php?id=1&page=1 to detail.html?id=1&page=1. I always get the 404 errors.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Martha676

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

You can't match the query string using RewriteRule. The RewriteRule pattern matches against the URL-path only, excluding the query string. You would need to use a RewriteCond directive and check against %{QUERY_STRING}. (So your directive never matches and you get a 404.)

However, it doesn't look like you need to match the query as you are simply rewriting the URL's "file" extension from .html to .php. Which could be done with something like:

RewriteRule ^detail.html$ detail.php [L]


The query string is automatically copied to the destination URL (providing you don't explicitly specify one in the substitution).

You should also escape the dot (eg. .) in the RewriteRule pattern (which is a regular expression), otherwise it will match any character.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme