2013-03-30 478 views
0

我需要添加一些重寫規則到網站。需要apache重寫規則幫助

這裏的想法=>

重寫從

(http or https)://(www. or no www.)example.com/whatever 
(http or https)://www.example.com/whatever 

所有非子域交通(所以基本上,總是強迫WWW)

此外重寫僅此1 sumbdomain =>

(http or https)://(www. or no www.)store.example.com/whatever 
(http or https)://www.example.com/whatever 

保留所有其他的s ubdomains完好無損。

到目前爲止,我有這個=>

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.com$ 
RewriteCond %{HTTP_HOST} ^store.example.com$ 
RewriteRule ^(.*)$ http%{ENV:askapache}://www.example.com/$1 [R=301,L] 

但它無法正常運行......

任何幫助將appriciated。

謝謝!

回答

1

啓用mod_rewrite的,並通過httpd.conf的.htaccess,然後把這個代碼在你.htaccessDOCUMENT_ROOT目錄:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^(?:store\.)?example\.com$ [NC] 
RewriteCond %{HTTPS}s on(s)| 
RewriteRule^http%1://www.example.com%{REQUEST_URI} [R=301,L] 
+0

非常感謝您的投入,但我得到了「此網頁有重定向循環」錯誤http://store.example.com/httpstore。://www.example.com .... – Andrej

+0

這是怎麼回事,因爲重定向的URI有主機www.example.com',這會導致這種情況失敗:'RewriteCond %{HTTP_HOST} ^(store \。)?example \ .com $ [NC]'。你在.htaccess中還有其他的東西嗎? – anubhava

+0

我做了一些小改動,你現在可以嘗試編輯的代碼嗎? – anubhava