Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Tue May 29, 2007 9:03 am
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?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Tue May 29, 2007 9:05 am
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?
Last edited by
superdezign on Tue May 29, 2007 9:06 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 29, 2007 9:06 am
Place them first.
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Tue May 29, 2007 9:22 am
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.
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Tue May 29, 2007 2:11 pm
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?
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Tue May 29, 2007 5:46 pm
Change it back to RewriteRule instead of RewriteCond and try again
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed May 30, 2007 2:15 pm
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
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed May 30, 2007 2:23 pm
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...
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed May 30, 2007 2:35 pm
Didn't work ... I'll investigate that though. Thanks.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed May 30, 2007 2:42 pm
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.
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed May 30, 2007 4:01 pm
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 .