Solved

Apache rewrite rule troubles

Posted on 2015-02-08
3
106 Views
Last Modified: 2015-02-09
I have the following in DocumentRoot/.htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !^on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Open in new window

The idea is that if the user supplies "http" instead of "https" it will rewrite to "https", thus forcing all requests to secure. That works fine for all files in and subordinate to DocumentRoot, even with subordinate .htaccess files, except I have on sub-directory that has its own .htaccess file that appears to be canceling out the upper directory .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^favicon\.ico$ skins/larry/images/favicon.ico

# security rules:
# - deny access to files not containing a dot or starting with a dot
#   in all locations except installer directory
RewriteRule ^(?!installer)(\.?[^\.]+)$ - [F]
# - deny access to some locations
RewriteRule ^/?(\.git|\.tx|SQL|bin|config|logs|temp|tests|program\/(include|lib|localization|steps)) - [F]
# - deny access to some documentation files
RewriteRule /?(README\.md|composer\.json-dist|composer\.json|package\.xml)$ - [F]
</IfModule>

Open in new window

For pages in this directory, if the user specifies https, fine, but if the user specified http, it does not get converted to https. I think something in this sub-folder's .htaccess rewrite rule is canceling out the superior rule, but I can't figure out what.
0
Comment
Question by:jmarkfoley
3 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40598968
The upper-level .htaccess file will always be processed first, so the lower-level file should not even come into play.  There may be some other part of your configuration that is interfering with this.  What actually happens when you browse to that directory without SSL?

Also, try enabling your rewrite log to see what is actually being processed.  Post a single failed attempt here, and we can help analyze it.
0
 
LVL 16

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40599074
Add this to your .htaccess in the sub-directory:

RewriteOptions Inherit

Open in new window


This will cause the sub-directory rules to be evaluated, then the parent directory rules on the second pass.
0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 40600026
Steve Bink:
The upper-level .htaccess file will always be processed first, so the lower-level file should not even come into play.
One would think so.
Post a single failed attempt here, and we can help analyze it.
I did the trace and the rewrite:trace messages did not appear to have the upper level .htaccess. However ...

Lucas Bishop: Yes, that did work! And the rewrite:trace shows it doing so. Thanks.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now