2016-03-04 52 views
1

我將如何改變htaccess的mod_rewrite的兩個查詢字符串參數路徑格式

http://example.com/?sort=top&time=variable 

http://example.com/top/variable 

&time=variable可能並不總是使用。

我目前的htaccess:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/?showcase/(.*?)/?$ /showcase.php?id=$1 [L] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /showcase\.php\?id=([^\&\ ]+) 
RewriteRule ^/?showcase\.php$ /showcase/%1? [L,R=301] 

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L] 

重寫http://example.com/showcase.php?id=inthttp://example.com/showcase/int

回答

1

如果代碼位於.htaccess文件中,請使用^而不是^/?。對於您的特定情況,您可以修改/添加到現有的重定向如下:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(top)(?:/([^/])+)?/?$ /?sort=$1&time=$2 [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?sort=(top)(?:&time=([^\s&]+))? [NC] 
RewriteRule^/%1/%2? [R=301,L] 
+0

這是行得通!非常感謝。我真的不能把我的腦袋寫下來,這似乎太複雜了 – frosty

相關問題