2011-07-13 32 views
0

GET變量我使用WordPress的永久鏈接結構類別%%/%postname%/與下面的htaccess:改寫URL

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

URL的採取的形式http://www.example.com/category/postname/。我有一個插件,如果您將?m=gallery附加到URL,它會將您帶到帖子的畫廊。所以http://www.example.com/category/postname/?m=gallery帶你到畫廊。我希望能夠使用http://www.example.com/category/postname/gallery/代替。我需要修改什麼才能達到我想要的效果?我會想象它會是這樣的RewriteRule ^(.+)/gallery$ $1?m=gallery

編輯 - 當前的htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

回答

1

考慮到你所提供的網址的例子(http://www.example.com/category/postname/gallery/ =>http://www.example.com/category/postname/?m=gallery),就需要這種線:

RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA] 
  1. 新增失蹤斜線/

  2. 添加了[QSA]標誌(實際上可能並不真正需要)。

你會需要在一些地方把這個規則在上面:這條線之後,例如:RewriteRule ^index\.php$ - [L]

顯然,可以確保WordPress會產生這樣的URL:這一切都http://www.example.com/category/postname/gallery/

+0

是有道理的,但它似乎沒有工作。你認爲WordPress正在做些什麼? – v0idless

+0

一個接一個的嘗試:1)將'QSA'添加到最後一個規則:'RewriteRule。 /index.php [QSA,L]'2)向答案中的規則添加'L'標誌3)如果仍然沒有,並且你完全控制Apache(可以編輯配置文件),那麼啓用重寫調試('RewriteLogLevel 9 '),請重新啓動httpd並查看重寫日誌(嘗試訪問此URL後) - 它應該向您顯示錯誤的位置。 – LazyOne