Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-22
3
Medium Priority
?
239 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 51

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 51

Accepted Solution

by:
Steve Bink earned 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

877 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