mod_rewrite 对 URL 中的子字符串进行修改
我使用 mod_rewrite 在我的网站上强制使用 HTTPS,但我想将 URL 中包含子字符串 com_bookmangement 的任何 URL 更改为 HTTP。
所以
http://www.example.com/index.php?option=com_content&view=article&id=85&Itemid=140
将被定向到
https://www.example.com/index.php??option=com_content&view=article&id=85&Itemid=140
但
https://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216
将被定向到
http://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216
我已经尝试过但没有成功:
#rewrite everything apart from com_bookmanagement to HTTPS
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} !com_bookmanagement=
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#rewrite vouchers views to http
#RewriteCond %{server_port} 443
RewriteCond %{REQUEST_URI} ^com_bookmanagement=
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]
有什么想法吗?
I'm forcing HTTPS on my site using mod_rewrite but I want to change this to HTTP for any URL with the substring com_bookmangement in the URL.
So
http://www.example.com/index.php?option=com_content&view=article&id=85&Itemid=140
will be directed to
https://www.example.com/index.php??option=com_content&view=article&id=85&Itemid=140
BUT
https://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216
will be directed to
http://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216
I've tried this without success:
#rewrite everything apart from com_bookmanagement to HTTPS
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} !com_bookmanagement=
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#rewrite vouchers views to http
#RewriteCond %{server_port} 443
RewriteCond %{REQUEST_URI} ^com_bookmanagement=
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用
^com_bookmanagement=
,则仅当com_bookmanagement=
出现在字符串开头时才会匹配。尝试不使用^
和=
。或者我会用什么:If you use
^com_bookmanagement=
it will only match ifcom_bookmanagement=
appears at the start of the string. Try it without the^
and=
. Or what I would use:使用
QUERY_STRING
而不是REQUEST_URI
进行条件:有关使用查询字符串重写 URI 的更多信息 此处。
Condition on
QUERY_STRING
instead ofREQUEST_URI
:More on rewriting URIs with query strings here.