Issue
I'm in charge of an Apache web server running some regular websites and some SSL websites. All of these websites are for company internal use. All websites are using VirtualHost directive. So I have
- http://siteA.mycompany
- http://siteB.mycompany
- http://siteC.mycompany
- https://siteD.mycompany
- https://siteE.mycompany
All running well and smoothly but some users complain to me that they have trouble accessing these websites because sometimes they must type http and sometimes they must type https ... (Administrator's job is so hard sometimes).
I'm looking to a way that solve this job: In case of requests coming with http protocol going to a website defined as using https requests must be redirected. The same work in reverse to be executed (https to http).
Another way to explain what I'm looking for:
* user request http://siteD.mycompany
* but website is define as using https protocol
* user's web browser change his request to https://siteD.mycompany
* user is no more bothered anymore by the bad protocol problem
Is there any tips / good practice to do such job? As there is a lot of websites concerned by this 'problem' the solution might be generic.
Solution
Please refer this Wiki article here
You will need these rules for each of your Virtual Host Configuration. Considering an example for https://siteD.mycompany
, you will need below Rewrite Rules to redirect Users to https
version of your site if http
is accessed.
<VirtualHost *:80 *:443>
ServerName siteD.mycompany
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>
Applying same logic for http://siteA.mycompany
, below rule can be used.
<VirtualHost *:80 *:443>
ServerName siteD.mycompany
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^/?(.*) http://%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>
For these rules to work you have to make sure that the virtual host configuration is accepting connections over both ports 80 and 443. Currently,there is a possibility that you have strict ports configuration because when you accessed https://siteD.mycompany
, 404 was thrown.
Good Luck!
Answered By - slash Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.