Link to home
Start Free TrialLog in
Avatar of dkern18195
dkern18195

asked on

https redirect

I want to redirect all pages in my site to https.  SSL is installed and I can type in the https for all files but want to automatically have https come up when a user enters the site.

Site is on apache server.

All my web searches do not give clear solutions.  I just need a simple htaccess file (I think)
Avatar of Maximus5684
Maximus5684
Flag of United States of America image

Add the following line to your httpd.conf file:

Redirect permanent / https://<address>/

Open in new window


Where <address> is the web address that you want redirected. Make sure to restart Aapache afterward.
Avatar of dkern18195
dkern18195

ASKER

I am not a server admin so I cannot restart the server.
Avatar of Graham N.
To handle this using a .htaccess file will require that the mod_rewrite module is loaded within Apache (if you are on shared hosting this is normally the default) then create a .htaccess file containing the following:


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}  [R=301,L]

Open in new window


Once the .htaccess file is written it's working,  there is no need to restart Apache
This gave an error.  Is there something I should have changed in the copy you provided?

The site is on a dedicated ip address.  Does that make a difference?
Server admins tell me that mod-rewrite is enabled on the servers
ASKER CERTIFIED SOLUTION
Avatar of Maximus5684
Maximus5684
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try a different approach:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://<yourdomainname>/$1 [R,L]

Open in new window


You should replace <yourdomainname> with your actual domain name.
One last way that I've found which does not use mod_rewrite and gets around some "double login" problems that can occur if you use authentication:

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "yoursite.com"
ErrorDocument 403 https://yoursite.com

Open in new window


Replace yoursite.com with your domain. This also does not tie it to a specific port if your site is being hosted on multiple ports.
Thank you both for helping with this.  I still need to test the last solution but this one worked
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI

The other took me to google search and brought up the domain at the top of the search.