2016-03-31 30 views
0

我想将https://example.com重定向到https://www.example.com为我的网站。你可以帮我把代码放在.htaccess文件中。该网站在magento。对non.www的https重写规则https。www.https on .htacces magento

+0

[通用htaccess的重定向到WWW非www]的可能的复制(http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) –

+0

我投票关闭这个问题作为脱离主题,因为堆栈溢出是[编程相关](http://stackoverflow.com/help/on-topic)问答网站。你的问题不是关于编程。也许你应该在http://magento.stackexchange.com上发布它呢? – Enigmativity

回答

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

解释:如果请求的主机不以www开始,重定向它开始以www

+0

Thankyou,但我需要的代码为HTTPS ..没有www重定向到与www –

+0

这是https的代码? – Garytje

0

来源|引用:http://codingbasics.net/magento-htaccess-file-optimized-speed-security-seo/

上面的链接有具有默认的Magento htaccess文件已针对速度和搜索引擎优化进行了优化,并且具有将非www重写为www的代码,但是没有用于将www重写HTTPS/SSL非www的代码。因此,我从上面的链接/站点抓取了htaccess代码部分,并对下面的代码进行了附加编辑,以便将HTTPS/SSL非www转换为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>