How to redirect all url to https except one?
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, drupal, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :# 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?
# 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).
Comments
Post a Comment