Blog Navigation
Partners
Latest Activity
Phil explains how to use the old telephone tones to wane off telemarketers!
Apache mod_rewrite (.htaccess), forcing www and https
I’m still working on other blogs for my site, but my other projects have sort of been put on hold because I don’t have all the information / tools / research I need to write them. So today I thought I’d write a short reference on .htaccess redirects for a problem I started researching yesterday and failed to get a quick answer to.
Using .htaccess, I wanted to force a website URL to always goto https://www.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.<DOMAIN>.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
All .htaccess files start with turning the RewriteEngine on.
RewriteCond is similar to an if statement, if the condition is true, run the next line. With that said, the second line checks to see if the website is being access via SSL / HTTPS (secure method). If it isn’t, the third rule takes whatever the url is and changes it to https://www.
Today was interesting because I didn’t know the 301 and 302 status codes off the top of my head, but now I have a good self-reference for the future
That is all I have for now. Hopefully I can get some Hadoop code posted in the near future that I promised a few blogs ago!
Tags: .htaccess, mod_rewrite, rewritenegine, rules, status code
Posted in Hosting / Server Administration, Programming, Technology