Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

More than 1 RewriteRule

Everytime I had another RewriteRule it doest work


Alternative Future

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

WebmasterWorld Senior Member 10+ Year Member

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.




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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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.


Alternative Future

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

WebmasterWorld Senior Member 10+ Year Member

Thanks again Jim

Appreciated :)


Featured Threads

Hot Threads This Week

Hot Threads This Month