Solved

Applying Apache <Directory> rules to all subdirectories except 2.

Posted on 2014-10-22
3
167 Views
Last Modified: 2014-12-15
Hi

What is the simplest way to apply these rules to all sub directories of "C:/Website" except for folders names "images" and "css"

<Directory "C:/Website/*/>">
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Directory>

Running Apache 2.4 on windows server.

Thankyou
0
Comment
Question by:mhdi
  • 2
3 Comments
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
The better question is why you would want to.  By forcing content pages to be SSL, and not enforcing the same policy for other resources, your users will likely receive mixed-content warnings in their browser.

Still, if you're sure this is the strategy you want, check out the DirectoryMatch container directive.  The Directory container allows some wildcards, but they will not match a directory separator character.  DirectoryMatch allows for the use of regex patterns, which gives better flexibility.
<DirectoryMatch "^C:/Website/.*(images|css)/">
    # ...
</DirectoryMatch>

Open in new window

0
 

Author Comment

by:mhdi
Comment Utility
If I did that, how do I ensure the instructions a processed in the correct order?

<DirectoryMatch "^C:/Website/.*/">
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</DirectoryMatch>
<DirectoryMatch "^C:/Website/.*(images|css)/">
   RewriteEngine Off
</DirectoryMatch>

Open in new window

0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
From the docs regarding how these containers are applied and merged:
Apart from <Directory>, each group is processed in the order that they appear in the configuration files. <Directory> (group 1 above) is processed in the order shortest directory component to longest. So for example, <Directory /var/web/dir> will be processed before <Directory /var/web/dir/subdir>. If multiple <Directory> sections apply to the same directory they are processed in the configuration file order. Configurations included via the Include directive will be treated as if they were inside the including file at the location of the Include directive.
0

Featured Post

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Join & Write a Comment

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

8 Experts available now in Live!

Get 1:1 Help Now