2011-06-29 42 views
0

對於我的應用程序,我希望將URL與mod_rewrite匹配,以便通過GET請求將URL直接傳遞到文件(index.php)。這是我的代碼:與mod_rewrite匹配的代碼

RewriteEngine On 
RewriteRule ^(.*)$ index.php?q=$1 

但是,它不工作,並且它似乎不定改寫爲「的index.php Q =的index.php?」。任何人都可以在這個問題上啓發我嗎? 謝謝。

回答

0
RewriteEngine On 

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

試試這個例子

+0

嘿,感謝回答,但它看起來像代碼不會通過URL作爲參數傳遞給PHP文件。你知道如何將'http://domain.com/user/example'改成http://domain.com/index.php?q =/user/example'嗎? – pyro

+0

UPD。我只是結合我們的例子)))它不會調用index.php?q = index.php,因爲RewriteCond%{REQUEST_FILENAME}!-f這種情況 –

+0

非常感謝。有用! :) – pyro