Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

A client wants to create a 301 to his new site that also happens to require ssl. Here's an example of what he wants:

http://www.abc.com  to https://www.efg.com
https://www.abc.com to https://www.efg.com
http://www.abc.com/product?id=1 to https://www.eft.com/product?id=1
https://www.abc.com/product?id=1 to https://www.eft.com/product?id=1

I'm reading up on using .htaccess file but it's not sinking in. Wondering if someone could present an example that would accomplish the above and explain it. Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This should do the trick:

RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]
RewriteRule ^(.*)$ https://www.efg.com/$1 [R=301,L]

and you'll need to repeat for any additional subdomains or edit above regex to match all subdomains by doing abc.com$ (no carat at beginning which means "begins with")

On RewriteRule, the ^(.*)$ means everything after domain/host. And with this section https://www.efg.com/$1, the $1 tells the first sub regex match element (the first thing in bracket) to be appeneded after www.efg.com/.

You can also do it via httpd.conf file.

<VirtualHost *>
  ServerName www.abc.com
  Redirect 301 / https://www.efg.com/
</VirtualHost>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.