2011-02-10 107 views
0

總之,我試圖改變給定的URL:mod_rewrite的替代查詢字符串鍵

http://mydomain.com/category/title/attachment/randomstring_?resolution=320x480 

隨着

http://mydomain.com/category/title/attachment/randomstring_320x480 

在本質上,從查詢字符串中刪除?resolution=和增加價值路徑。

類別,標題和randomstring值是動態的,但它們的位置應始終相同。

我不知道它是否重要,但這是在WordPress中使用。

我嘗試以下,但我只是得到一個404:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} ^resolution=([0-9]{3,4}x[0-9]{3,4})$ 
RewriteRule ^$ ${REQUEST_URI}%1/? [R] 

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

任何幫助表示讚賞;)

回答

1

好,大量的試驗和錯誤(和閱讀RewriteLog輸出後),我終於得到了它的工作如下:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 

RewriteCond %{QUERY_STRING} ^resolution=(.*)$ 
RewriteRule . %{REQUEST_URI}%1? [R=301,L] 

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

與原來的解決方案的關鍵問題:

  • RewriteRule
  • RewriteRule
  • 使用^$代替.使用/?,而不是僅僅?不包括在RewriteRule標誌,L

對於任何人誰是好奇,包括?RewriteRule防止QUERY_STRING保留在請求中。