问题原文
原帖链接 · Abdus Sattar Bhuiyan · CC BY-SA 4.0
# Go to https if not on firmware
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/firmware$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# Go to http if you are on firmware
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/firmware$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
This code should redirect /firmwire to http instead of https. But example.com/firmware redirect to example.com/index.php. whats problem is going on?
The code is run on apache server and drupal 7. Any idea?
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
# Go to http if you are on firmware RewriteCond %{SERVER_PORT} !80 RewriteCond %{REQUEST_URI} ^/firmware$ [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]This code should redirect
/firmwiretohttpinstead ofhttps.
Both your code blocks redirect to HTTPS. In fact, you would expect the above to trigger a redirect loop since it is potentially redirecting to itself. That is unless /firmware is a physical filesystem directory - or it's not actually being processed at all?
But
example.com/firmwareredirect toexample.com/index.php
This suggests you have a conflict with existing directives - perhaps your redirects are in the wrong place? The order of mod_rewrite directives is important.
These directives need to go near the top of your .htaccess before the Drupal front-controller.
These directives can also be tidied a bit; no need for the additional condition that checks the URL-path. This check should be performed by the RewriteRule pattern. For example:
# Go to https if not on firmware
RewriteCond %{SERVER_PORT} 80
RewriteRule !^firmware$ https://www.example.com%{REQUEST_URI} [NC,R,L]
# Go to http if you are on firmware
RewriteCond %{SERVER_PORT} !80
RewriteRule ^(firmware)$ http://www.example.com/$1 [NC,R,L]
The NC flag is only required if /firmware really can be mixed case.
If /firmware is a physical filesystem directory then this may need modifying (as mod_dir will, by default, append a trailing slash).
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
