Welcome to WebmasterWorld Guest from 54.221.75.115

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 Permanent redirect

     
7:06 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


To redirect any pages from a previous website to the home page of another, which one would be correct in the .htaccess file please? and would anything else be needed in the file?

Redirect 301 / http://www.newdomain.com/


Or:

RewriteEngine on

RewriteBase / RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
7:32 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


In case it helps, both domains are on the same server.
7:43 pm on Feb 22, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15257
votes: 692


Rules in Redirect by that name use mod_alias.
Rules in RewriteRule use mod_rewrite.

The two modules don't interact well together. So the moment you have a single RewriteRule--which you should, because it's the only way to make a canonicalization redirect (domain name or protocol)--you need to change any existing mod_alias rules to use mod_rewrite syntax.

It doesn't matter whether they are on the same server or not.

This is all bypassing the initial problem, which is
To redirect any pages from a previous website to the home page of another
You do not want to do this.

The question of what you do want to do will depend on the real-life circumstances. For this you need to set aside the Apache code and explain in English what the situation is, and what you want to do.
7:51 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


It's all in perfect English, Lucy - it's been my native language since birth.
8:16 pm on Feb 22, 2018 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4056
votes: 251


It is a bad idea to 301 redirect all pages to a single page, Google routinely sees these as a soft 404 error. 404s don't hurt you but soft 404s should be avoided. Ideally, old pages are redirected using rewrite rules (Apache's mod_rewrite) to the new version that replaces them. The rules as written use mod_alias as lucy24 said, that can cause unexpected results and even loops depending on what else is in your .htaccess file. Even if nothing else is in the htaccess file right now, using mod_alias can make future changes more problematic. (How do you handle https or www/non www canonicalization?) Your custom error handling preferences and cache settings belong in that file also.

So the answer to your two questions imho is "neither form" and "yes".
8:27 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


Thank you for that friendly reply, basically, both domains are on the same server, and the previous domain olddomain.com needs to 301 redirect to the new domain newdomain.com - bearing that in mind, how would you do it please?
8:42 pm on Feb 22, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11453
votes: 173


the previous domain olddomain.com needs to 301 redirect to the new domain newdomain.com - bearing that in mind, how would you do it please?

i would 301 redirect (using mod_rewrite directives) the urls from olddomain, on a one-to-one basis, to the url containing equivalent content on newdomain.
any requests for urls on olddomain that have no equivalent on newdomain should get a 410 Gone response.
you can also use mod_rewrite directives for this purpose. (RewriteRule with a [G] flag specified)
8:44 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


Thanks Phranque, I was trying to avoid that, as there's about 250/300 pages on each of the old and new domains.
9:00 pm on Feb 22, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11453
votes: 173


are the url paths similar on both olddomain and newdomain?
are there patterns in the urls that make the legitimate urls easily identifiable?
are there patterns in the urls that make the "translatable" during the redirect?
these are all helpful to all get it done in .htaccess with minimal work.

another option is to internally rewrite (using mod_rewrite directives) all requests to a script.
then let the script examin the requested url and provide the appropriate redirect response (301 status code and Location: header) or a 404/410 status code if necessary.
you can maintain a database or even use flat files (tab/comma separated values) to keep a list of url paths that should be redirected and the redirect path, and another list of no longer existing content that should get a 410 response.
anything else (not on either list) should get a 404.
9:07 pm on Feb 22, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 410
votes: 0


Thanks for that, the answer to the 1st 3 questions, are no.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members