?
Solved

Mod Rewrite

Posted on 2006-03-28
5
Medium Priority
?
1,255 Views
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   ^(.*)$  https://mywebsite.com$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:

/test.php
/dev/test.php
/xsl

thanks

0
Comment
Question by:axman505
  • 2
3 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 16314838
Just adjust/add a condition:

RewriteEngine on
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{REQUEST_URI} !^/(dev/)?test\.php$
RewriteCond %{REQUEST_URI} !^/xsl/
RewriteRule   ^(.*)$  https://mywebsite.com$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).
0
 
LVL 1

Author Comment

by:axman505
ID: 16317464
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   ^(.*)$  https://mywebsite.com$1  [R,L]


0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 16320427
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:....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 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