?
Solved

Apache rewrite rule troubles

Posted on 2015-02-08
3
Medium Priority
?
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

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 18

Accepted Solution

by:
Lucas Bishop earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

801 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