Apache redirect

Sigma721

Well-Known Member
Joined
Sep 14, 2011
Messages
122
Reaction score
0
Hi everyone

First off I am new to both Apache and Linux.

I have my site working through port 443 as ssl, but now want to redirect all traffic to any of the pages on my site to use ssl instead of port 80.

I have tried researching this, but all the write ups go on about virtual hosts, which I do not have. I am just hosting a single website on the server and need all traffic to run through port 443.

Can anyone help me out?
 
You could try using a .htaccess file in the root of your site with a simple redirect rule.
Googling for: apache .htaccess force ssl
would get lots of examples like:
http://davidwalsh.name/force-secure-ssl-htaccess

Simply create a text file named ".htaccess" and enter the following lines:
Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

Replacing the domain.com with your actual domain name. Save this file in the root of your website. Don't get the name of the file wrong. It really does begin with a period.

These lines instruct Apache to check if a web browser is requesting any page over port 80. If it is then perform the rule to redirect the web browser to the same page but over ssl.

It may fail to work if your server does not have Apache's mod_rewrite enabled.
 
Top
Sign up to the MyBroadband newsletter
X