1

I am having some issues with URL re-writing that I cannot figure out. Here's the problem.

This URL IS NOT redirecting properly:
http://domain.com/index.php?en=oldpage

HOWEVER, this URL IS redirecting properly:
http://www.domain.com/index.php?en=oldpage

The only difference in the url that is not redirecting properly is the absence of the www.

Here is the re-write I am using:

RewriteCond %{QUERY_STRING} ^en=oldpage
RewriteRule ^(index.php/|)$ /newpage.html? [R=301,L]

I also have this re-write BEFORE other re-writes, to handle url's without "www.":

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Why will it not re-direct without the "www." ? Any help would be much appreciated. Thank you.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
ADP
  • 39
  • 4
  • Can you define `not redirecting properly`? Does it mean that or not redirecting at all? Do you have the rules in the same order as you've put them here in the question? – arco444 Jul 29 '15 at 14:13
  • As in not redirecting properly. It just returns user to the homepage (www.domain.com) and not the intended re-write. I have the re-write: RewriteCond %{HTTP_HOST} !^www\. ... first, before the RewriteCond %{QUERY_STRING} ^en=oldpage ... will change in question to be more clear. – ADP Jul 29 '15 at 14:17
  • Is your canonical `www` working? The pattern `^(index.php/|)$` in your `RewriteRule` wouldn't match either the example URLs you've posted (with or without `www`), so there is certainly "something else" going on here. – MrWhite Jul 29 '15 at 15:58
  • re-write works fine now. server related issue I was not aware of. thanks – ADP Jul 29 '15 at 20:58

1 Answers1

0

I guess there is some code/rule below those rules adding query string back to your URLs.

Try these rules instead based on THE_REQUEST variable which doesn't get overwritten:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?en=oldpage [NC]
RewriteRule ^ /newpage.html? [R=301,L]

Make sure to test it after clearing your browser cache.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I removed my old re-write and tried your example after clearing cache... Still works the same way as the old re-write. Only works on URL containing "www." – ADP Jul 29 '15 at 14:59