Friday, January 18, 2019

apache 2.2 - LAMP Server HTTP-> HTTPS redirect in .htaccess




I have 2 LAMP servers with the same version of Apache, both running Wordpress.
SSL is working on both servers (although the test server uses a cert for a different domain).



On both I have the following .htaccess file (/var/www/html/.htaccess):



# BEGIN WordPress

RewriteEngine On


RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]




# END WordPress


The test server redirects to HTTPS correctly, but the production server does not attempt to redirect at all. I can manually browse the production site via HTTPS.



The permissions on the .htaccess file is 755 and owned by apache:apache on both server.



In order to make sure that the redirect on the test site was because of the .htaccess file, I changed it by removing the following:





RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]



The redirect on on the test site stopped until I added it back.



Is there something that may have been done on the test site that needs to be done on production?


Answer




I found the issue so I guess I jumped the gun on posting this question, but I'll leave it here - maybe it will save somebody some time.



In the /etc/httpd/conf/httpd.conf file, I had AllowOverride set to None still on the production site for the document root directory.
Here is what it looks like now (with the redirect working):





#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks


#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#

Order allow,deny
Allow from all



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...