I want to redirect https://example.com to https://www.example.com for my website. Can you help me with the code to put it on .htaccess file. the site is in magento.
Asked
Active
Viewed 66 times
0
-
Possible duplicate of [Generic htaccess redirect www to non-www](http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – Maximilian Gerhardt Mar 31 '16 at 15:04
-
I'm voting to close this question as off-topic because Stack Overflow is a [programming-related](http://stackoverflow.com/help/on-topic) Q&A site. Your question is not about programming. Perhaps you should post it on http://magento.stackexchange.com instead? – Enigmativity Apr 01 '16 at 22:55
2 Answers
0
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Explained: If the requested host does not start with www., redirect it to start with www

Garytje
- 874
- 5
- 11
-
Thankyou , BUT I need the code for HTTPS.. without www redirect to with www – H.krishna Mar 31 '16 at 15:14
0
Source|Reference: http://codingbasics.net/magento-htaccess-file-optimized-speed-security-seo/
The link above has a default Magento htaccess file that has been optimized for speed and SEO and has code for rewriting non-www to www, but does not have the code for rewriting HTTPS/SSL non-www to www. So I have grabbed the htaccess code section from the link/site above and made the additional edits to the code below for rewriting HTTPS/SSL non-www to www.
##### Search Engine redirects and rewrites for SEO purposes #####
<IfModule mod_rewrite.c>
# Rewrite|Redirect http to https|SSL & non-www to www
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
##### Redirect away from /index.php and /home
##### Warning: This index.php rewrite will prevent Magento
##### Connect from working. Simply comment out the
##### following two lines of code when using Connect.
##### Please note - https://www. if not using www simply use https://
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ https://www.yourdomain.com/$1 [R=301,L]
##### Please note - https://www. if not using www simply use https://
redirect 301 /home https://www.yourdomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>

Ed-AITpro
- 310
- 1
- 8