2017-01-19 131 views
1

我期待獲得以下2頁來重定向WWW。各自主機的版本;重定向非www到WWW的http和https

http://website.co.uk > redirect to > http://www.website.co.uk 

https://website.co.uk > redirect to > https://www.website.co.uk 

我需要保持HTTP和對各個URL進行工作HTTPS。

回答

1

您可以使用此單一規則在兩個httphttps添加www

# for Apache 2.4+ use this rule 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^%{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

如果」重新使用舊的Apache版本,然後使用以下規則:

# for Apache 2.2 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTPS}s on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE] 
+0

導航到內部頁面時,它會將每個頁面重定向到/index.php。例如,當你訪問http://website.com/en/for-suppliers/supplier-solutions時,你會被重定向到http://www.website.com/index.php而不是http://www.website。 com/en/for-suppliers/supplier-solutions,因爲它應該是? –

+0

如果您將此重定向作爲第一條規則放置在「RewriteEngine On」行的下方並清除瀏覽器緩存,則不會發生此問題。 – anubhava

0

您是否嘗試使用RewriteEngine規則? 下面應該做的伎倆(應用它的兩個虛擬主機80和443):

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ https://www.website.co.uk$1 [R=301,L] 
#for 80 port: RewriteRule ^(.*)$ http://www.website.co.uk$1 [R=301,L] 
相關問題