zefon
asked on
redirect mydomain.com to www.mydomain.com
I would like to know how to do the following:
redirect mydomain.com to www.mydomain.com
Currently when a user types in mydomain.com the can browse the website just the same as using www.mydomain.com. This creates a problem on SSL pages because the cert is for www.mydomain.com and when users access the site using mydomain.com they get a warning that the site name does not match the cert. How can I automatically redirect anyone who types in mydomain.com to www.mydomain.com.
Keep in mind that the solution needs to be global because there are search engine listings for links such as mydomain.com/directory/fil e.html and I would want these automatically change to www.mydomain.com/directory/file.html. Manually entering each file in an htaccess file is not an option.
redirect mydomain.com to www.mydomain.com
Currently when a user types in mydomain.com the can browse the website just the same as using www.mydomain.com. This creates a problem on SSL pages because the cert is for www.mydomain.com and when users access the site using mydomain.com they get a warning that the site name does not match the cert. How can I automatically redirect anyone who types in mydomain.com to www.mydomain.com.
Keep in mind that the solution needs to be global because there are search engine listings for links such as mydomain.com/directory/fil
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, this would also work for SSL.
"Do I need to use a separate RewriteCond and RewriteRule for each or can I combine it all it one?"
Take a look at the syntax in the SitePoint link above. It shows how you can use it for a single site or for all sites on the server depending on where you place it.
"Do I need to use a separate RewriteCond and RewriteRule for each or can I combine it all it one?"
Take a look at the syntax in the SitePoint link above. It shows how you can use it for a single site or for all sites on the server depending on where you place it.
ASKER
I have other domain names pointing to this site and I took your code and it worked on them too. Do I need to use a separate RewriteCond and RewriteRule for each or can I combine it all it one?
Example:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.com ^domain2\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
or this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain2\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
Do I need the RewriteEngine on for each instance or only once?
Also, for SSL would this work?
RewriteEngine on
RewriteCond %{HTTPS_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=permanent,L]