2013-08-29 29 views
0

你好,我需要顯示的index.php的內容全部沒有找到URL, 例如找不到網址顯示的index.php內容

http://domain.com/random must show http://domain.com/index.php content 
http://domain.com/random/random.html must show http://domain.com/index.php content 
http://domain.com/random/rand/random.php must show http://domain.com/index.php content 

我嘗試下面的代碼,但我仍然得到未找到錯誤

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

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

回答icabod is working :)謝謝 – Vishnu

回答

1

這裏的問題是,你包括在重寫URL請求的路徑的一部分,通過使用$1,從而有效地插入規則到新的URL的第一部分括號。這意味着您對http://domain.com/random/rand/random.php的請求會嘗試返回文件http://domain.com/random/index.php

此外,您的規則與您的第一個示例不匹配,因爲該URL不包含/,這是您的正則表達式所需的。

相反,如果請求的URL是不是一個文件或目錄(或鏈接),那麼就重寫一切到的index.php:

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule .* /index.php [L,R] 

請注意,我已經添加了R標誌,這意味着請求系統(瀏覽器)會看到URL已經改變......不知道這是否是你想要的。

+0

嗨,有時候它運行良好,有時它會一直重定向到同一頁面? – Vishnu

+0

對不起我的壞,它工作正常:) +1 – Vishnu