htaccess的重写规则和条件 [英] .htaccess rewriterule and condition
问题描述
大家好我尝试使用的.htaccess改变我的网址,但得到一个问题 我的URL看起来像这样
www.example.com/web-search.php?q=car&limit=15
我想把它像
www.example.com/web/cars/15
但没有成功我不明白的问题,请大家帮帮我。谢谢 这是我的.htaccess code
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^(GET | POST)\ /web-search\.php\?q = \&AMP(*);限= \ HTTP(*?)
重写规则^ / 2%/ 3%? [R = 301,L]
重写规则^网/([^ /] *)/([^ /] *)$ /web-search.php?q=$1&limit=$2 [L]
它的工作原理是我从重写URL删除网页/但随后的URL看起来像
www.example.com/cars/15
我不想我要添加网页/也。在此先感谢
更新1:
这造成问题的原因是上面提到的重写规则
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^(GET | POST)\ /search\.php\?q = \&AMP(*);限= \&放大器; SIZ = \ HTTP(*)(*?)
重写规则^ / 2%/ 3%/ 4%? [R = 301,L]
重写规则^([^ /] *)/([^ /] *)/([^ /] *)$ /search.php?q=$1&limit=$2&siz=$3 [L]
这是由两方面的疏忽。第一条规则不网页添加到URL。第二条规则中包含之间^
正则表达式的其余部分流氓空间,使其返回一个错误。
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^(GET | POST)\ /web-search\.php\?q = \&AMP(*);限= \ HTTP(*?)
重写规则^ /网络/ 2%/ 3%? [R = 301,L]
重写规则^网/([^ /] *)/([^ /] *)$ /web-search.php?q=$1&limit=$2 [L]
记住要清除这个测试之前,您的浏览器缓存,您的浏览器可能会缓存旧的,错误的,重定向。
Guys I am trying to change my url using .htaccess but getting one problem My URL looks like this
www.example.com/web-search.php?q=car&limit=15
I want to turn it like that
www.example.com/web/cars/15
but not succeeding I don't get the problem please help me. Thanks Here is my .htaccess code
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /web-search\.php\?q=(.*)\&limit=(.*?)\ HTTP
RewriteRule ^ /%2/%3? [R=301,L]
RewriteRule ^ web/([^/]*)/([^/]*)$ /web-search.php?q=$1&limit=$2 [L]
It works it I remove "web/" from the rewrite url but then url looks like
www.example.com/cars/15
which I don't want I want to add web/ also. Thanks in advance
Update 1:
This causing the problem it is above the mentioned rewrite rule
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /search\.php\?q=(.*)\&limit=(.*)\&siz=(.*?)\ HTTP
RewriteRule ^ /%2/%3/%4? [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /search.php?q=$1&limit=$2&siz=$3 [L]
This is caused by two oversights. The first rule does not add "web" to the url. The second rule contains a rogue space between the ^
and the rest of the regex, causing it to return an error.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /web-search\.php\?q=(.*)\&limit=(.*?)\ HTTP
RewriteRule ^ /web/%2/%3? [R=301,L]
RewriteRule ^web/([^/]*)/([^/]*)$ /web-search.php?q=$1&limit=$2 [L]
Remember to clear your browser cache before testing this, as your browser might have cached the old, wrong, redirect.
这篇关于htaccess的重写规则和条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!