Switch to https

Switch to https - .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 apache, htaccess, mod-rewrite, , .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 :


I'm looking to use an .htaccess file to use mod_rewrite to switch the protocol from http:// to https:// when someone hits my website.



For instance, once someone goes to:
http://www.mywebsite.com/



I'd like the browser to switch to:
https://www.mywebsite.com/



The same goes for the http://mywebsite.com/ -> https://mywebsite.com



This is the following code I've been using and I've experienced some odd things so if anyone could provide me with information if this is the right way to do it, or if you have a better way, please provide it. Thanks in advance.



RewriteEngine On
RewriteCond %SERVER_PORT !=443
RewriteRule ^(.*)$ https://www.ebaillv.com/$1 [R=301,L]

Solution :

You could try checking for HTTPS instead of whether the port is 443. Also, the rule below matches everything and redirects it to exactly the same as it was but with the https. You could probably throw the [R=301, L] at the end of it if you wanted.



RewriteEngine On
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST%REQUEST_URI

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect