: 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.
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.
More posts by @Martha676
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.