: RewriteRule /change-email.htm?e=someone@somewhere.com&h=xxxxxx I need to rewrite URL's of this form: /change-email.htm?e=someone@somewhere.com&h=xxxxxx to: /change-email/?e=someone@somewhere.com&h=xxxxx
I need to rewrite URL's of this form:
/change-email.htm?e=someone@somewhere.com&h=xxxxxx
to:
/change-email/?e=someone@somewhere.com&h=xxxxx
I've done this in my .htaccess:
RewriteCond %{REQUEST_URI} ^/change-email.htm$
RewriteCond %{QUERY_STRING} ^e=(.*)&h=(.*)$
RewriteRule ^(.*)$ /change-email/?e=%1&h=%2 [R=301,L]
but this is rewriting:
/change-email.htm?e=someone@somewhere.com&h=xxxxxx
to:
/change-email/?e=someonesomewhere.com&h=xxxxx
Note that it is removing the @ symbol. Any suggestions on how to make this work?
UPDATE
Using
www.example.com/change-email.htm?e=someone@somewhere.com redirects perfectly
however:
example.com/change-email.htm?e=someone@somewhere.com redirects to
example.com/change-email/?e=someonesomewhere.com (@ symbol removed)
Here's my complete .htaccess:
RewriteEngine On
RedirectMatch 301 /images/(.*) /wp-content/uploads/
RewriteRule ^gv5.htm(.*) /get-v5-key/ [R=301,L]
RewriteRule ^change-email.htm(.*)$ /change-email/ [R=301,NE,L]
RewriteRule ^unsubscribe.htm(.*)$ /unsubscribe/ [R=301,NE,L]
RewriteRule ^renew-support.htm(.*)$ /renew-support/ [R=301,NE,L]
RewriteRule ^retrieve-license-code.htm(.*)$ /retrieve-registration-key/ [R=301,NE,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE
Answered my own question.
More posts by @Shelton105
2 Comments
Sorted by latest first Latest Oldest Best
Problem was a WordPress one. It was stripping out the @ when re-writing the non www address to the www address. Problem resolved by adding my old redirect code (which I thought I could dispense with) to top of the .htaccess file:
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) www.example.com/ [R=301,L]
You might be able to resolve this by using the NE (noescape) flag on the RewriteRule directive? However, this is admittedly a little puzzling, as even special characters shouldn't be removed entirely, just converted to their hexcode equivalent. The NE flag allows special characters to be passed through untouched.
However, your current rules can be greatly simplified and improved.
Currently, every single request is being processed by the RewriteRule pattern ^(.*)$, so this is inefficient. You only need to process requests for /change-email.htm, so this can be rewritten as a one liner (no RewriteCond directives are required):
RewriteRule ^change-email.htm$ /change-email/ [R=301,NE,L]
Note that the RewriteRule is processed first. Only when the RewriteRule pattern matches are the preceeding RewriteCond directives processed.
You don't need to match against the query string since you aren't doing anything with it, except passing it straight through to the substitution - which is the default behaviour.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.