2010-11-13 71 views
3

我已經從我的域中刪除了該博客,並改爲使用簡單的index.html。 如何重定向所有傳入流量,使其不顯示404錯誤,但重定向到索引?htaccess重定向除索引頁面以外的所有內容

我嘗試這樣做,但它循環......

RewriteEngine on 
RewriteRule ^(.*)$ /index.html [L,R=301] 

回答

7

嘗試:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/index.html 
RewriteRule ^(.*)$ /index.html [L,R=301] 

正如你所說,這是不行的,我想嘗試:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/aaa.html 
RewriteRule ^(.*)$ /aaa.html [L,R=301] 

index.html是一個通用的默認文件名,因此可能存在服務器級別的規則,而不是在.htaccess中。雖然這取決於服務器設置。

+0

它不起作用。如果我去這裏,它顯示一個重定向循環錯誤。 http://invalid.org/category/catname – user478419 2010-11-13 15:28:31

+0

我剛剛在本地嘗試過,它工作正常。這是服務器上唯一的重寫規則嗎?你可以嘗試其他的東西,比如將index.html改爲aaa.htm嗎? – 2010-11-13 15:58:54

+0

wget -O- localhost/category/catname --2010-11-13 10:56:44-- http:// localhost/category/catname 發送HTTP請求,等待響應... 301永久移動 位置: http://localhost/index.html [following] - 2010-11-13 10:56:44-- http://localhost/index.html 將現有連接重用到localhost:80。發送,等待響應 HTTP請求...... 200 OK 長度:177的text/html] 保存到:'STDOUT」

它的工作原理!

2010-11-13 10:56:44(7.95 MB/s) - 寫入stdout [177/177] – 2010-11-13 16:00:19

0

嘗試添加

Options +FollowSymLinks -MultiViews -Indexes 

在最高層,並給它一試。

相關問題