2012-12-28 171 views
3

我試圖從URL的末尾刪除字符串:刪除查詢字符串

例如,我有這樣的結構:

http://sitename.com/category/first-category-name/?post_type=question 
http://sitename.com/category/second-category-name/?post_type=question 
http://sitename.com/category/...-category-name/?post_type=question 

我想從URL的末尾刪除?post_type=question

我喜歡很多關於stackoverflow的例子,但沒有人爲我工作。

謝謝。

回答

9

這很簡單,只需使用:

RewriteCond %{QUERY_STRING} "post_type=" [NC] 
RewriteRule (.*) /$1? [R=301,L] 

如果你打算將它添加到WordPress的網站,你需要之前的任何WordPress的規則添加:

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

但經過

RewriteBase/
2

就做這樣的事情:

RewriteEngine On 
RewriteBase/
# Make sure there is a query string 
RewriteCond %{QUERY_STRING} . 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* /? [R=301,L] 

放置一個?末存在時刪除查詢。