[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Apache rewrite rule troubles

Posted on 2015-02-08
3
Medium Priority
?
181 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

649 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