Solved

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

Posted on 2014-10-22
3
192 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
ID: 40398434
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
ID: 40405363
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
ID: 40405631
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Website URL redirection 10 79
Ways to assess https/ssl websites 3 110
Best practices for sharing large amounts of data 9 107
Let's Encrypt - Auto Renew Failure via Cron Job 1 22
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
What You Need to Know when Searching for a Webhost Provider
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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