繁体   English   中英

htaccess mod_rewrite两个查询字符串参数为路径格式

[英]htaccess mod_rewrite two query string parameters to path format

我将如何改变

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

如果代码在.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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM