2013-06-02 40 views
5

我想重寫所有www.site.com/hello to www.site.com/index.php?p=hello ,並將它與下面的代碼工作(在.htaccess):的RewriteCond負條件

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

但我想繼續工作,所以www.site.com/?p=hello將留www.site.com/?p=hello

舊鏈接

我嘗試下面的代碼,但它不會工作

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(\?p=) 
RewriteRule ^([^/]*)/?$ /index.php?p=$1 

回答

5

我我找到了答案。

錯誤是試圖獲得GET參數REQUEST_URI。正確的用法應該是這樣的QUERY STRING

RewriteCond %{QUERY_STRING} !(p=.*)$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]*)/?$ /index.php?p=$1