SOLVED::Do i park or redirect with domain change?

Hi,
I developed a website at a temporary domain (.org). The domain name was then changed in whm to the live domain (.org.uk). In cPanel I parked the .org and also set up a 301 redirect for the .org > .org.uk
However after 5 weeks or more i can still access the old domains pages…the don’t redirect to the new domain. The home page does redirect but any old pages are still viewable so for instance …org/login does not redirect to …org.uk/login so this is confusing users.

This is what is written to the .htaccess:

RewriteCond %{HTTP_HOST} ^myWebsite.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.myWebsite.org$
RewriteRule ^/?$ “http://www.myWebsite.org.uk” [R=301,L]

Why am i still seeing web pages at the development domain and how can I remedy this?
Do i need to add 301’s for each of the old domains pages?
Thanks for any help
G

RewriteRule ^/?$ "http\:\/\/www.myWebsite.org.uk/$1" [R=301,L]

That ought to do it.

g171,

You were close but no cigar.

First, combine the RewriteCond statements and use the No Case flag (the {HTTP_HOST} is case sensitive)

Second, do NOT use backslashes in your redirection.

Finally, your RewriteRule was trying ONLY to match the null URI (a domain only request). Try:

[code]RewriteEngine on
RewriteCond %{HTTP_HOST} myWebsite.org [NC]

or just .org$ [NC]

RewriteRule .? http://www.myWebsite.org.uk%{REQUEST_URI} [R=301,L][/code]

That will retain the requested file and ensure that you’re at your .co.uk domain. My “or just” was an abbreviated version of the RewriteCond which specifies that only your myWebsite.org will be matched (CASE SENSITIVE) but isn’t necessary if you’re hosting any other .org domains.

You might benefit from reading the mod_rewrite tutorial at http://dk.co.nz/seo as it contains explanations and sample code. It’s helped many SitePoint members over the years and should help you, too.

@metho - that won’t work because you have not defined the $1 variable in the RewriteRule AND you’ve not shown that the RewriteCond matching the .org version of the domain (resulting in a loop if not present).

Regards,

DK

Hi,
Thanks for your answers.
@metho - Thank so much that seems to have sorted it out:-)
@dklynn - JFYI - unfortunately if i replace the redirect code (generated via parking and redirection in cpanel), with your code I get a redirect loop. I’m new to .htaccess so it’s all gobbledygook at the moment but thought it might be useful for you to know.

Cheers both very much.
G

G171,

Yup! Sorry about that! I had in my mind that you were redirecting to .co.uk so there would have been no conflict with the .org TLD. Instead, use[code]RewriteEngine on
RewriteCond %{HTTP_HOST} myWebsite.org$ [NC]

or just .org$ [NC]

RewriteRule .? http://www.myWebsite.org.uk%{REQUEST_URI} [R=301,L][/code]
Mea culpa (“the hurrier I go, the behinder I get.”).

Regards,

DK

Hi DK
Thanks again. So is your method above better than simply adding:
RewriteRule ^/?$ “http://www.myWebsite.org.uk/$1” [R=301,L]

If so why?

g171,

Oh, my! You didn’t read the posts above?

  1. NEVER use backslashes in a redirection.

  2. Your regex can only match a null URI.

  3. Without a RewriteCond statement to prevent a redirection if the .org.uk version of your domain had been requested, your code will be “loopy.”

  4. $1 was never created so it would be null.

My code corrects ALL those errors AND retains the requested URI (at the .org.uk version of your domain). If you don’t want to retain the requested URI, simply delete the %{REQUEST_URI} in the correct (non-backslashed) version of the redirection.

As I had also stated, my error was in not providing the end anchor (the $) after .org BECAUSE I had it in my mind that you were redirecting to .co.uk rather than .org.uk … and I did apologize for that!

ALL that information was provided above.

Regards,

DK

Hi DK,
Yeah I did read your post but being new to htaccess and with that other line of code seemingly working as expected (albeit with back slashes) I just went with it until further explanation. I will try your code later when i get chance as it’s obviously the more robust solution given your thorough description.
Thanks again, i appreciate you taking the time
:smile:

G177,

No problem, mate!

My apologies for letting my frustration show, too.

If you have any specific questions, let me know (preferably via PM).

Regards,

DK

Or even here, so that everyone learns. :wink:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.