簡體   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