2012-02-29 192 views
0

我有重寫規則,它對www以外的子域起作用。我要強制所有URL開始以www,並用PHP處理所有的.html:在.htaccess上重寫規則重定向

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\. [NC] 
RewriteRule ^catalog\.html$ http://www.domain.com/static.php?staticpage=$1 [L] 

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

如果你打http://domain.com/catalog.html,它成功地重定向到http:// www.domain.com/catalog.html(當然沒有空間),因爲該文件不存在。或者,如果catalog.html存在,它將只顯示http:// www.domain.com/catalog.html並呈現實際的.html文件(不含空格)。

我試圖實現http://www.domain.com/catalog.html而不顯示瀏覽器上的static.php,無論文件是否存在。 static.php應該處理每個.html頁面

在此先感謝!

回答

1

最後 COND正則表達式的%的變量,你需要的條件才能成功所以怎麼樣:

RewriteCond %{HTTPS}s ^..(s?) 
RewriteRule^  -  [E=PROTO:http%1] 

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^   %{ENV:PROTO}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
0

我假設你要顯示的static.php內容當請求.html文件對於。沒有static.php顯示在瀏覽器上。

使用時,http://發生外部重定向,導致地址顯示在瀏覽器上。

RewriteCond %{HTTP_HOST} ^www\. [NC] 
RewriteRule (.+)\.html$ static.php?staticpage=$1 [L] 

對於HTTPS你可以遵循什麼@TerryE已建議。 但是,我不明白你要重定向到哪個頁面https