2014-11-01 54 views
0

我的.htaccess文件是:與URL重定向怪改寫

RewriteEngine on 

RewriteRule (.*) index.php?_url=$1 [QSA,L] 

它完全在大多數情況下。但是,如果請求的網址存在爲真實文件夾,它會變得瘋狂。

例如,當我請求/random它被改寫爲index.php?_url=random,狀態碼200,但對於/static(這是在Web服務器上的現有目錄),它提供了301重定向到/static/?_url=static

回答

0

使用這個下面的代碼爲的.htaccess

<IfModule mod_rewrite.c> 
    Options -MultiViews 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
</IfModule> 
+0

但是我怎樣才能得到原始的請求uri從PHP? – vsakos 2014-11-01 11:07:34

0

如果你想排除被重寫現有的文件和目錄,具有RewriteCond

這樣做
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?_url=$1 [QSA,L]