Htaccess 通过匹配 url 字符串和参数进行 URL 重定向
我需要匹配 URL 格式,并根据 URL 匹配需要将传入请求重定向到不同的页面。
例如
http://www.domain.com/path1/path2/ 错误网址 -1/ ?var1=val1
http://www.domain.com/path1/path2/ another-wrong-url -1/ ?var1=val1
http://www.domain.com/path1/path2/ 第三个错误的网址 -1/?var1=val1
http://www.domain.com/path1/path2/ Fourth-wrong-url -1/?var1=val1
查看高亮显示的 URL 匹配项。它始终将 -1 作为 url 字符串。 。那需要重定向一个静态页面。
而其他一些 URL 始终将 var1 作为 URL 查询字符串参数。因此,如果 URL 将 var1 作为查询字符串,则需要将这些 URL 重定向到另一个静态页面。
所以我尝试了这个但没有成功。请帮助我完成这个重定向脚本
RewriteEngine on
RewriteRule ^(path1/path2/[^-1]*)$ http://www.domain.com/target-page [L,R=301]
I need to match the URL format and depends on URL matches need to redirect the incoming requests to different pages.
For example
http://www.domain.com/path1/path2/ wrong-url -1/ ?var1=val1
http://www.domain.com/path1/path2/ another-wrong-url -1/ ?var1=val1
http://www.domain.com/path1/path2/ third-wrong-url -1/?var1=val1
http://www.domain.com/path1/path2/ fourth-wrong-url -1/?var1=val1
See the High lighted URL Matches. It always having -1 as the url string. . That needs to be redirected one static page.
And some other URL's always have var1 as URL Query String parameter. So if URL have var1 as Query string then those URL's needs to be redirected to another Static page.
So i tried this but didn't worked. Please help me in this redirecting script
RewriteEngine on
RewriteRule ^(path1/path2/[^-1]*)$ http://www.domain.com/target-page [L,R=301]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1. 以
-1/
结尾的 URL 规则:2. 查询字符串中包含
var1=
参数的规则:注意:
通过这些规则,现有的查询字符串也将传递到新的 URL(例如
/path1/path2/wrong-url-1/?say=meow
将变为http://www. domain.com/target-page?say=meow
)。要删除它,请在目标 URL 末尾添加?
(例如http://www.domain.com/another-target-page? [L,R=301]
1. Rule for URL that ends with
-1/
:2. Rule for having
var1=
parameter in query string:NOTE:
With these rules existing query string will be passed to a new URL as well (e.g.
/path1/path2/wrong-url-1/?say=meow
will becomehttp://www.domain.com/target-page?say=meow
). To drop it, add?
at the end of target URL (e.g.http://www.domain.com/another-target-page? [L,R=301]