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)
Site is on apache server.
All my web searches do not give clear solutions. I just need a simple htaccess file (I think)
ASKER
I am not a server admin so I cannot restart the server.
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:
Once the .htaccess file is written it's working, there is no need to restart Apache
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Once the .htaccess file is written it's working, there is no need to restart Apache
ASKER
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?
The site is on a dedicated ip address. Does that make a difference?
ASKER
Server admins tell me that mod-rewrite is enabled on the servers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try a different approach:
You should replace <yourdomainname> with your actual domain name.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://<yourdomainname>/$1 [R,L]
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:
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.
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "yoursite.com"
ErrorDocument 403 https://yoursite.com
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.
ASKER
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.
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.
Open in new window
Where <address> is the web address that you want redirected. Make sure to restart Aapache afterward.