使用查询字符串重写规则
Rewrite rule with query string
需要一些关于重写规则的帮助。
如何将一个 url with query 重定向到另一个 url with query?
示例:
http://example.com/prject/test.php?key=1
重定向到
http://example.com/prject/test.php?id=1
还有
http://example.com/prject/file2.php?key=1
到
http://example.com/prject/file2.php?arg=1
.htaccess 文件位于 /project/ 目录。
试试这个:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^key=([^&]+) [NC]
RewriteRule ^ http://example2.com/prject/test.php?key=%1 [NC,R,L]
在您的 /project/.htaccess
文件中,插入以下内容:
RewriteEngine On
RewriteBase /project/
# Redirect test.php?key=<number> to test.php?id=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^test.php$ test.php?id=%1 [R,L]
# Redirect file2.php?key=<number> to file2.php?arg=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^file2.php$ test.php?arg=%1 [R,L]
需要一些关于重写规则的帮助。 如何将一个 url with query 重定向到另一个 url with query? 示例:
http://example.com/prject/test.php?key=1
重定向到
http://example.com/prject/test.php?id=1
还有
http://example.com/prject/file2.php?key=1
到
http://example.com/prject/file2.php?arg=1
.htaccess 文件位于 /project/ 目录。
试试这个:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^key=([^&]+) [NC]
RewriteRule ^ http://example2.com/prject/test.php?key=%1 [NC,R,L]
在您的 /project/.htaccess
文件中,插入以下内容:
RewriteEngine On
RewriteBase /project/
# Redirect test.php?key=<number> to test.php?id=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^test.php$ test.php?id=%1 [R,L]
# Redirect file2.php?key=<number> to file2.php?arg=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^file2.php$ test.php?arg=%1 [R,L]