homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
More than 1 RewriteRule
Everytime I had another RewriteRule it doest work
Alternative Future




msg:4113587
 4:19 pm on Apr 10, 2010 (gmt 0)

Greetings to the forum

If I use just one of the below RewriteRules it works fine, but when I try to add another into the .htaccess file it doesnt work. I want mod_rewrite to detect if there is only one dir/ in the path and use that rule and move onto the next rule if there is two dir/dir/ and then finally onto the third if it detects dir/dir/dir.

RewriteEngine on
#Match only the first directory use [L] to say continue to next rule if this one doesnt match
RewriteRule ^([^/\.]+)/?$ execute/index?cmd=display&var1=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ execute/index?cmd=display&var1=$1&var2=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ execute/index?cmd=display&var1=$1&var2=$2&var3=$3 [L]

I also tried adding the following to my .htaccess to see what debug was coming out:
RewriteLog "/path_to_log/mod.log"
RewriteLogLevel 3

As soon as I put that in I get the following error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

TIA

-Gs

 

jdMorgan




msg:4113640
 7:37 pm on Apr 10, 2010 (gmt 0)

An obvious problem is that any URL-path that matches any rule will be rewritten to a format that matches your first rule. As a result, it will be rewritten again -- and again, and again, until the server gives up, and you will be left with a call to "index" (which isn't a valid file as far as I can tell), with a query string of var1="index".

You need to exclude the target path from being rewritten by adding a negative-match RewriteCond on the first rule. You can use it to check that $1 does Not match "index" or that ${REQUEST_URI} does Not match "/index" -- either will work.

As documented, RewriteLog and RewriteLogLevel are not available in a per-driectory mod_rewrite context. They are available only at the server-config level, and so will cause a server error if used in .htaccess files.

Jim

Alternative Future




msg:4113656
 8:36 pm on Apr 10, 2010 (gmt 0)

Thanks again Jim

Appreciated :)

-Gs

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved