2011-11-17 64 views
0

如果文件或目錄存在,我不想將所有內容重定向到index.php exepept。我嘗試了谷歌的幾種方式,但這確實減慢了網站的速度,並且沒有真正起作用,所以我覺得我錯了。將所有內容重定向到index.php

所以URL是這樣的:

 
    `site.com/Projects/S01/ -> site.com/Projects/S01/index.php (original)` 
    `site.com/Projects/GE5/ -> site.com/Projects/GE5/index.php (original)` 
    `site.com/Projects/  -> site.com/index.php` 
    `site.com/Websites/  -> site.com/index.php` 
    `sits.com/Testifcate/ -> site.com/index.php` 

請告訴我這樣做的最快的方法?我嘗試過的所有方法都很慢。 謝謝。像main.css這樣的文件在加載時也非常慢,也許這些文件不會執行檢查以使其更快?什麼是最好的方式去做這件事?

回答

2

這是我重寫規則,做到了這一點:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 
0

這是否對你的工作:

 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^$ 
RewriteCond %{HTTP_HOST} ^domain.com$ 
RewriteRule ^$ http://domain.com/index.php [L,R=301] 

我希望它可以幫助

1

嘗試以下操作:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f # ensures it's not a file 
RewriteCond %{REQUEST_FILENAME} !-d # ensures it's not a directory 
RewriteRule . index.php [L,QSA] # . matches all, and routes to index.php if the above conditions do not match 
+0

(°。°)我不知道**''**可以代替** **(*。**)** **重寫規則。 index.php [L,QSA]'**。但是,嘿!我很確定你的解決方案是正確的。 –

+0

圓括號用於捕獲我們不需要的子表達式。 '.'將匹配URL中的任何字符。所以規則匹配不管。然後檢索URL,你可以使用'$ _SERVER ['REQUEST_URI']'' –

相關問題