Friday, November 09, 2012
How to redirect non-www URLs to www URLs in Apache
Below is the answer on how redirect your traffic to www URLs.
E.g.
http://domain.com -> http://www.domain.com
https://domain.com -> https://www.domain.com
Q: Why would you need it?
A: Search engines will regard those as different pages with duplicate content.
http://www.thesitewizard.com/apache/redirect-domain-www-subdomain.shtml
You can either put this code in .htaccess file or inside your site configuration under
/etc/httpd/conf/sites-enabled
Non-SSL redirection goes within <VirtualHost *:80> </VirtualHost>:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L]
SSL redirection goes within <VirtualHost *:443> </VirtualHost>:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=permanent,L]
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment