homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Advice needed about complex htaccess 301
The_Hat




msg:4364438
 7:25 pm on Sep 19, 2011 (gmt 0)

I built a dynamic website to replace a website we were paying a provider for. We will continue to own the previous domain but will also be utilizing a new domain. I plan to basically 301 the old domain to the new domain but I have questions..

First of all, the previous site didn't differentiate between www and non www.. so there are pages indexed in google with both URLS.. second there are some particular section index type URLs that I would like to 301 to the URL of same section front in the new site.. but then I would also want to 301 all the other possible requests for the old domain to the home page (or perhaps a better page for usability, TBD)..

I know how to redirect www to non www.. individual pages to other individual pages and entire domains to other domains.. but I am concerned about how exactly the syntax should be done when writing an htaccess that will do all the above at the same time.

 

The_Hat




msg:4364441
 7:31 pm on Sep 19, 2011 (gmt 0)

Is it correct to just string them all together.. e.g. first redirect www to non www.. then next do the individual page 301s... and then after that in the file redirect the entire domain.. would the entire domain redirect since it's at the bottom page do clean up detail on anything that hadn't already been sent on? Thanks.

g1smd




msg:4364455
 7:49 pm on Sep 19, 2011 (gmt 0)

If you redirect non-www to www then do the individual redirects you will create an unwanted multiple-step redirection chain for some requests.

You should list the individual page redirects first and the more general non-www to www redirect last.

There should be no redirects within the old site. Requesting any of the old URLs should cleanly redirect to the correct URL on the new site in one step.

Your file on the old site will have a long list of rules, listed from most specific to most general.

Use RewriteRule for all of your rules. Do not use Redirect or RedirectMatch at all.

The_Hat




msg:4364459
 7:55 pm on Sep 19, 2011 (gmt 0)

ahh.. so old specific urls to new specific urls.. then www to non.. and then entire domain.

and the syntax would be the same as if I was using those pieces individually?

lucy24




msg:4364535
 9:57 pm on Sep 19, 2011 (gmt 0)

Think of it as a cascade. Here I'm assuming you're adding www. (And, ahem, using a format that nobody could possibly mistake for cut-and-paste ;))

{olddomain}/{directory}/{page} -> {www.newdomain}/{directory}/{page}

Bye-bye to that page. Repeat as necessary for other pages, using pipes (page1|page2|page3) with $1 as appropriate.

{olddomain}/{directory} -> {www.newdomain}/{directory}

Bye-bye to that directory. Repeat as above. This step will only pick up the material that wasn't already dealt with in the previous step.

Finally sweep up the leftovers:

{olddomain} -> {www.newdomain}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved