2012-05-25 36 views
0

我試圖做基於此條件下一個htaccess重定向:的.htaccess重定向[除的index.php力WWW]

重定向沒有 「www」 的http://siteweb.comhttp://www.siteweb.com/index.html 所有頁面除http://siteweb.com/index.php

http://siteweb.com/index.php必須被重定向到http://www.siteweb.com/index.php

其實我用這個代碼[但蹊蹺的就可以了:S]

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule !^/index.php$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteCond %{REQUEST_URI} ^/index\.php$ [NC] 
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] 

在此先感謝。

回答

0

你可以在你的.htaccess使用此代碼:

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule (?!^index\.php$)^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NC] 

這將所有的URI重定向除了index.php到域與www。但是你的問題是混淆了,因爲你也寫道:

The http://siteweb.com/index.php must to be redirected To http://www.siteweb.com/index.php

告訴我,可能是想每一個URI重定向包括index.phpwww域。

+0

謝謝四你的快速回復,但對於第二種情況,我希望http://siteweb.com/index.php => http://www.siteweb.com/index.php http:// siteweb。 com/* => http://siteweb.com/index.HTML 其實您的代碼只適用於site.com => www.site.com – user1271775