Link to home
Start Free TrialLog in
Avatar of axman505
axman505

asked on

Mod Rewrite

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

Avatar of caterham_www
caterham_www
Flag of Germany image

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).
Avatar of axman505
axman505

ASKER

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]


ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial