Solved

Apache rewrite rule troubles

Posted on 2015-02-08
3
98 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

12 Experts available now in Live!

Get 1:1 Help Now