我将如何更改
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=int
重写为http://example.com/showcase/int
。
答案 0 :(得分: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]