Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

Changing domain names with mod_rewrite

apache experts wanted!

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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/

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

10+ Year Member



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!

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month