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
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
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]
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).