Changing Site Domain
Quick htaccess question
I am changing the domain associated with a site and want to know if I can setup the htaccess to make the following types of redirects:
Redirect http://www.oldomain.com/contact-us
to http://www.newdomain.com/contact-us
Basically a global redirect that redirects to the new domain but keeps the rest of the URL that the user typed.
UPDATE: I ended up using the 开发者_StackOverflow社区following code and it works perfectly
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
Sure, you can do this easily without having to mess with cryptic RewriteEngine commands. (RewriteEngine has its place, but it's certainly not needed for something as simple as this.)
Redirect permanent / http://newdomain.com/
The Redirect directive automatically preserves anything following the portion of the path it's been instructed to redirect. The documentation for the Redirect directive explains this with an example:
Example:
Redirect /service http://foo2.bar.com/service
If the client requests
http://myserver/service/foo.txt
, it will be told to accesshttp://foo2.bar.com/service/foo.txt
instead.
This should do it for you.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldname\.com
RewriteCond %{REQUEST_URI} ^oldname\.com
RewriteRule ^(.*)$ http://www.newname.com/$1 [R=301,QSA,L]
Batfan,
If you control your own httpd, perhaps you can check on the settings of NameVirtualHost directive in httpd.conf. See http://httpd.apache.org/docs/2.0/mod/core.html#namevirtualhost
By default, httpd is not configured to do name-based virtual hosting. You need to enable that through NameVirtualHost. Afterwards, try to do the redirects as suggested by Greg Hewgill.
Let us know if that works.
Thanks, Ismael Casimpan
精彩评论