homepage Welcome to WebmasterWorld Guest from 54.235.61.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Changing domain names with mod_rewrite
apache experts wanted!
franklin dematto




msg:1520649
 5:43 am on Apr 3, 2003 (gmt 0)

The official domain name of a site has changed from aaa.com to bbb.com. I'd like to use apache's mod_rewrite to issue a permanent redirect from any request with host aaa.com or www.aaa.com to bbb.com, with the same uri. Like this:

[aaa.com...] -> [bbb.com...]

for any dir/file etc.

This is complicated by a few things:
1) I only want to redirect requests that set a host to aaa.com or www.aaa.com. But if they issue no host, or different versions of bbb.com (like www.bbb.com or subdomain.bbb.com etc), I don't want to redirect it

2)Some URI's have changed, and I want to fix these in one redirect, and not have to do two:
ie [aaa.com...] -> [bbb.com...] in one permanent redirect

I can't seem to get the rewrite rules right! Can anyone help me?

Also, for reasons currently beyond my control, the rules must be done in the .htaccess, not the main httpd.conf

 

gethan




msg:1520650
 6:22 am on Apr 3, 2003 (gmt 0)

First split up the directories for each host... make your problem simpler. eg. www.domain.com has a different root to domain.com.

Then have a look here: [webmasterworld.com...] - simple example... your rules should be along the lines of

(spot the q's :))

.htaccess in the olddir -> newdir directory

rewriteEngine on
rewriteBase /olddir/
rewriteCond %{HTTP_HOST} ^olddomain.com$ # says must be only olddomain.com not www.olddomain.com
rewriteRule ^(.*) httq://newdomain.com/newdir/$1 [L,R=301] # gets the directory move.

.htaccess in the main directory

rewriteEngine on
rewriteBase /
rewriteCond %{HTTP_HOST} ^olddomain.com$ # says must be only olddomain.com not www.olddomain.com
rewriteRule ^(.*) httq://newdomain.com/$1 [L,R=301] # gets the directory move.

Could spend some time rewriting this into a single .htaccess - my mod_rewrite is a little rusty atm though. Good luck - and I hope this sends you on the right track.

===
In general (for other visitors) there are simpler methods that you should consider if:
- you don't have any deep links.
- users don't have bookmarks to deep pages.

They include

[webmasterworld.com...]

mod_alias:
RedirectMatch 301 /english/(.*\.html)$ htt*://www.newsite.com/$1

permenant redirect:
RedirectPermanent / httq://www.newurl.com/

franklin dematto




msg:1520651
 12:03 am on Apr 4, 2003 (gmt 0)

Thanks, gethan, it worked! I think the problem I had was that I did not include the RewriteBase rule (what does it do?).

I have one more issue, though: The old site used URL's like this: aaa/Services/index.html . The new one does not use html (rather php), and the urls are all to the directory : bbb/Services/ . How can I make one rule to redirect 301 all URLS of the form aaa/****/index.html to bbb/****/? I'd like to do this with one redirect, the spiders may get scared off by a double one...

Thanks!

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