开发者

mod_rewrite on substring in URL

开发者 https://www.devze.com 2023-01-09 14:49 出处:网络
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.

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.e开发者_JAVA技巧xample.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?


If you use ^com_bookmanagement= it will only match if com_bookmanagement= appears at the start of the string. Try it without the ^ and =. Or what I would use:

#rewrite everything apart from com_bookmanagement to HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{QUERY_STRING} !(^|&)option=com_bookmanagement(&|$)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#rewrite vouchers views to http
RewriteCond %{HTTPS} !=off
RewriteCond %{QUERY_STRING} (^|&)option=com_bookmanagement(&|$)
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


Condition on QUERY_STRING instead of REQUEST_URI:

RewriteCond %{SERVER_PORT} !443
RewriteCond %{QUERY_STRING} !com_bookmanagement
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} com_bookmanagement
RewriteRule ^/(.*)$ http://www.mysite.com/$1 [R=301,L]

More on rewriting URIs with query strings here.

0

精彩评论

暂无评论...
验证码 换一张
取 消