Forum Moderators: phranque
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
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/
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!