2011-04-30 79 views
1

我的網站的網址是www.site.comhtaccess的重寫的index.php和重定向如果加www

如果用戶訪問= site.com我需要301重定向到www.site.com網站

如果用戶訪問= www.site.com/index.php/asd我需要301重定向到www.site.com/asd

如果用戶訪問= site.com/asd我需要301重定向到www。 site.com/asd

是所有這些條件從.htaccess文件可能嗎?有人可以幫助我嗎? :)

感謝;)

+0

相關:http://serverfault.com/questions/145109/howto-redirect-http-to- HTTPS-ON-THE-相同的httpd – cregox 2011-05-03 15:41:48

回答

0

在.htaccess文件請嘗試以下規則:

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

RewriteCond %{THE_REQUEST} ^GET\s/index.php [NC] 
RewriteRule ^index.php/(.*)$ /$1 [R=301,L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 

RewriteCond %{HTTP_HOST} ^site\.com$ [NC] 
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,NC] 
+0

呃... ... tryed它的工作原理,但不是definitly:P – moment 2011-05-01 20:34:53

+0

我的意思是代碼重定向我從site.com到www.site.com但如果我去site.com/asd它重定向我www.site.com/index.php/asd而我想被重定向到www.site.com/asd – moment 2011-05-01 20:41:06

+0

這是很奇怪的。你確定以上是你的.htaccess文件中唯一的代碼嗎?沒有上面的地方發送到'index.php/asd'。事實上,上面的第二個RewriteRule將'index.php/asd'設置爲'/ ads'。如果你可以粘貼access.log的相關部分片段,這也有助於調試。 – anubhava 2011-05-01 20:58:26