2016-03-31 28 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>