Reputation: 359
I am trying to write a htaccess redirect, but it is not working as I want it to. My current (working) htaccess redirects all html pages with 1 character to the index file as:
RewriteRule ^([a-zA-Z0-9]).html$ index.php?letter=$1
So a.html gets redirected to index.php?letter=a Now I need to redirect the page a.html?page=2 to index.php?letter=a&page=2 Basically I want to redirect the url, but leave the dynamic part intact. All of the following return a 404:
RewriteRule ^([a-zA-Z0-9]).html?page=([0-9]+) index.php?letter=$1&page=$2
RewriteRule ^([a-zA-Z0-9]).html?page=(.*) index.php?letter=$1&page=$2
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule ^([a-zA-Z0-9]).html(.*) index.php?letter=$1&page=%1
I think I'm close, but I can't seem to get there :/ could anyone give me the last push?
Upvotes: 1
Views: 2111
Reputation: 51711
Your RewriteRule
needs to be
RewriteRule ^([a-zA-Z0-9])\.html$ index.php?letter=$1 [QSA,NC,L]
Please, note that URL parameters are not available for matching within the RewriteRule
. If you simply need to append an extra URL parameter you can do so along with the [QSA]
flag which would take care of appending the original URL parameters for you.
Please, note that the dot before html
needs to be escaped \.
as well. The [L]
makes sure that rewriting stops and no further rules (if any below) are applied.
Upvotes: 2