Page 1 of 1
Mod Rewire (Rule)
Posted: Tue May 29, 2007 9:03 am
by AliasBDI
I have some working rewrite rules. The first group of lines tell the server to parse all urls with folder paths as query strings. For example,
domain.com/string1/string2/ would be parsed as
domain.com/details.php?var1=string1&var2=string2.
Code: Select all
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ /details.php?nav_ID=$1
RewriteRule ^([A-Za-z0-9-]+)(/([A-Za-z0-9-]+))/?$ /details.php?nav_ID=$1&pg_ID=$2
# eControl rewrite
RewriteRule ^/eControl(/([A-Za-z0-9-]+))/?$ /eControl/index.php
RewriteRule ^/eControl$ /eControl/index.php
RewriteRule ^/eControl/$ /eControl/index.php
My problem is that I have a particular folder in the web site called 'eControl' that should not follow that rule. So I added a rule below it that rewrites this. For example,
domain.com/eControl/string would be parsed as
domain.com/eControl/string. However, it is not working. What I need is the script to tell the server to ignore all url strings with "eControl" in them. Any ideas?
Re: Mod Rewire (Rule)
Posted: Tue May 29, 2007 9:05 am
by superdezign
Maybe it's following the first rules first, so by the time the URL gets to the eControl rules, it's already been changed.
Can't rewrite rules have conditions BEFORE they actually occur? Like, if the folder name is not eControl, THEN mod_rewrite?
Posted: Tue May 29, 2007 9:06 am
by feyd
Place them first.
Posted: Tue May 29, 2007 9:17 am
by vigge89
I suggest checking out the apache mod_rewrite documentation, it's very helpful;
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Posted: Tue May 29, 2007 9:22 am
by AliasBDI
Ahhhh ... I used put the lines at the top as suggested and then changed the directive from RewriteRule to RewriteCond. Thanks for the help. Works fine now.
Posted: Tue May 29, 2007 2:11 pm
by AliasBDI
Well, apparently that was my cache. It really does not work. Two lines have conflicts:
Code: Select all
RewriteCond ^/eControl(/([A-Za-z0-9-]+))/?$ /eControl/index.php$todo=$1
RewriteRule ^([A-Za-z0-9-]+)/?$ /details.php?nav_ID=$1
I tried a varity of ways with this code, but evidently, the order is correct, but they are conflicting. Any ideas?
Posted: Tue May 29, 2007 5:46 pm
by vigge89
Change it back to RewriteRule instead of RewriteCond and try again

Posted: Wed May 30, 2007 2:15 pm
by AliasBDI
If it is set back to RewriteRule then it is ignored all together.
Code: Select all
RewriteRule ^eControl/([A-Za-z0-9]+)/?$ /eControl/index.php$todo=$1
RewriteRule ^([A-Za-z0-9-]+)/?$ /details.php?nav_ID=$1
RewriteRule ^([A-Za-z0-9-]+)(/([A-Za-z0-9-]+))/?$ /details.php?nav_ID=$1&pg_ID=$2
Posted: Wed May 30, 2007 2:23 pm
by superdezign
I'm not very experienced in mod_rewrite but, last I checked, RewriteCond applied to the RewriteRule that it is paired with. So, make your RewriteCond only let the RewriteRule apply when eControl is not in the URL (Unless, of course, I'm mistaken).
Code: Select all
RewriteCond %{REQUEST_URI} (^eControl)
I think...
Posted: Wed May 30, 2007 2:35 pm
by AliasBDI
Didn't work ... I'll investigate that though. Thanks.
Posted: Wed May 30, 2007 2:42 pm
by superdezign
AliasBDI wrote:Didn't work ... I'll investigate that though. Thanks.
Yeah, I'm sure my regex is wrong, but I'm positive that this is the way the RewriteCond works.
Posted: Wed May 30, 2007 4:01 pm
by AliasBDI
I got it to work! This code worked:
Code: Select all
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/eControl)
RewriteRule ^([A-Za-z0-9-]+)/?$ /details.php?nav_ID=$1
RewriteCond %{REQUEST_URI} !(/eControl)
RewriteRule ^([A-Za-z0-9-]+)(/([A-Za-z0-9-]+))/?$ /details.php?nav_ID=$1&pg_ID=$2
It will rewrite all URL strings except those that begin with
/eControl.