重定向 - 总共 4 个参数
Redirect - 4 total parameters
@anubhava 和 @RavinderSingh13 通过这个脚本继续帮助我学习并取得今天的进步。这是我目前所拥有的:
##1st rule with one parameter: $id--
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id= [L,QSA,NC]
##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=&class= [NC,L,QSA]
##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=&name= [NC,L,QSA]```
现在,我想再添加一条只有 一个 参数而不是两个参数的规则。但是,这个参数在url中使用了PHP$_GET['name']。我正在尝试添加一条重写 http://IPADDRESS.com/file.php?name=JohnDoe to http://IPADDRESS.com/newdirectory/JOHNDOE.
的规则
谢谢!
使用您显示的示例,请尝试执行以下操作。请确保在测试您的网址之前清除浏览器缓存。
RewriteEngine ON
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id= [L,QSA,NC]
##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=&class= [NC,L,QSA]
##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=&name= [NC,L,QSA]
##Rule with two parameters: $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?name=(\S+)\s [NC]
RewriteRule ^ /directory/%1? [R=301,L]
RewriteRule ^directory/([^/]*)/?$ /directory/file.php?name= [NC,L,QSA]
@anubhava 和 @RavinderSingh13 通过这个脚本继续帮助我学习并取得今天的进步。这是我目前所拥有的:
##1st rule with one parameter: $id--
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id= [L,QSA,NC]
##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=&class= [NC,L,QSA]
##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=&name= [NC,L,QSA]```
现在,我想再添加一条只有 一个 参数而不是两个参数的规则。但是,这个参数在url中使用了PHP$_GET['name']。我正在尝试添加一条重写 http://IPADDRESS.com/file.php?name=JohnDoe to http://IPADDRESS.com/newdirectory/JOHNDOE.
的规则谢谢!
使用您显示的示例,请尝试执行以下操作。请确保在测试您的网址之前清除浏览器缓存。
RewriteEngine ON
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id= [L,QSA,NC]
##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=&class= [NC,L,QSA]
##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=&name= [NC,L,QSA]
##Rule with two parameters: $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?name=(\S+)\s [NC]
RewriteRule ^ /directory/%1? [R=301,L]
RewriteRule ^directory/([^/]*)/?$ /directory/file.php?name= [NC,L,QSA]