Mod Rewrite

Posted on 2006-03-28
Last Modified: 2008-01-09
I have the following example of code in my apache configuration file for a virtual host:

RewriteEngine on
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_FILENAME} !^/test\.php$
RewriteRule   ^(.*)$$1  [R]

This works fine for this file.  However, now i have 2 files, and a directory which I want to be accessible via http, and force the rest to be accessible via https.

The following i want to allow http access to are:



Question by:axman505
    LVL 27

    Expert Comment

    Just adjust/add a condition:

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !=443
    RewriteCond %{REQUEST_URI} !^/(dev/)?test\.php$
    RewriteCond %{REQUEST_URI} !^/xsl/
    RewriteRule   ^(.*)$$1  [R,L]

    Better use REQUEST_URI, REQUEST_FILENAME might contain sometimes not the same value of REQUEST_URI (that is the case when an uri-to-filename translation already took place).
    LVL 1

    Author Comment

    I always thought you needed to have [OR] after rules.  Isnt how this is requiring all to be matched?  Wouldn't it need to be:

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !=443
    RewriteCond %{REQUEST_URI} !^/(dev/)?test\.php$ [OR]
    RewriteCond %{REQUEST_URI} !^/xsl/
    RewriteRule   ^(.*)$$1  [R,L]

    LVL 27

    Accepted Solution

    This is a logical AND:

    match every request (RegEx RewriteRule) --> server port is not 443 and --> REQUEST_URI is not /test.php, /dev/test.php and --> REQUEST_URI does not start with /xsl/ ----> 302 redirect https:....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    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…
    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 …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now