Welcome to WebmasterWorld Guest from 3.214.184.124

Forum Moderators: bakedjake

Message Too Old, No Replies

Mod Rewrite and Redirection

Moving to a new domain

     
9:31 am on Mar 22, 2006 (gmt 0)

New User

10+ Year Member

joined:Mar 22, 2006
posts:5
votes: 0


Hi..
I recently moved my site and blog from one domain to another.
To automatically redirect visitors from the old domain to the new one, I created a php file which gives an 301 permanent redirection as shown below:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.net");
exit();
?>

Now this redirects correctly and if someone visits the base url, all is fine. But if someone visits the permalink of an old article, it still redirects to www.example.net instead of the url with the domain changed to the new one.
So, for example,

going to [siteOne.net...] redirects to [siteTwo.net...] instead of [siteTwo.net...]

Is there some way to achieve the redirection with the trailing uri remaining intact and hence going to the page itself?

I'm using Apache 1.3.33 on a debian linux system.

Thanks in advance :)

3:22 pm on Mar 22, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 30, 2003
posts:428
votes: 0


Sure, the request is in the environment (REQUEST_URI), so you can adjust your Location parameter accordingly.

Alternatively, .htaccess works well

RedirectMatch Permanent /(.*) http://example.com/$1

3:47 pm on Mar 22, 2006 (gmt 0)

New User

10+ Year Member

joined:Mar 22, 2006
posts:5
votes: 0


I was thinking of moving to .htaccess as well..

I tried the following:


RewriteEngine on

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

But the issue was that since this is for a subfolder, it worked when there was a trailing slash or a longer url but failed for the folder name without a trailing slash.

So, "http://subdomain.old-site.net/foldername/" and "http://subdomain.old-site.net/foldername/somefile" both get redirected correctly, "http://subdomain.old-site.net/foldername" did not forward correctly but infact forwarded to the new domain appended with the filesystem path of that directory.
eg. "http://subdomain.new-site.net//home/username/public_html/aj/foldername" which of course is incorrect.

I would prefer to use a 301 redirect so as to maintain my page rank as well as easily allow SEs to locate the new site..

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members