Rule breaks when keyword matches existing directory

Oh, the strange things mod_rewrite does!

Rule breaks when keyword matches existing directory

Postby hawkmoon » Thu Oct 06, 2005 4:38 am

The below rule doesn't work - because 'help' is also a subdirectory.

RewriteRule ^help$ main.php?menu=help [L]

So if I request http://host.bar.org/mywebsite/help, I end up at http://host.bar.org/mywebsite/help/?menu=help (rather than http://host.bar.org/mywebsite/main.php?menu=help)

mod_rewrite log:

11.70.215.999 - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (2) init rewrite engine with requested uri /mywebsite/help
11.70.215.999 - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (1) pass through /mywebsite/help
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (3) [per-dir /var/www/html/mywebsite/] strip per-dir prefix: /var/www/html/mywebsite/help -> help
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (3) [per-dir /var/www/html/mywebsite/] applying pattern '^help$' to uri 'help'
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (2) [per-dir /var/www/html/mywebsite/] rewrite help -> main.php?menu=help
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (3) split uri=main.php?menu=help -> uri=main.php, args=menu=help
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (3) [per-dir /var/www/html/mywebsite/] add per-dir prefix: main.php -> /var/www/html/mywebsite/main.php
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (2) [per-dir /var/www/html/mywebsite/] strip document_root prefix: /var/www/html/mywebsite/main.php -> /mywebsite/main.php
999.215.broadband3.foo.org - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (1) [per-dir /var/www/html/mywebsite/] internal redirect with /mywebsite/main.php [INTERNAL REDIRECT]
11.70.215.999 - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (2) init rewrite engine with requested uri /mywebsite/help/
11.70.215.999 - - [06/Oct/2005:11:37:17 +0100] [host.bar.org/sid#8dfce48][rid#8fb45a0/initial] (1) pass through /mywebsite/help/
.
.
.

If I rename the subdirectory or keyword to 'Help', it works.

Any ideas? Please? :eek2:
hawkmoon
 
Posts: 4
Joined: Fri Aug 12, 2005 1:21 pm

Postby seomike » Tue Oct 25, 2005 6:52 am

The solution is a rewritecond. Since our proxy subdirectories are going to be fake and not exist we just tell the mod to look for subdirectories that are not real.

#If the folder doesn't exist on the server then try and push it through the mod
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule^somedir/([^/]+)/?$ somedir/menu.php?dir=$1
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby hawkmoon » Thu Nov 03, 2005 11:59 am

First, let me thank you for replying. I had actually given up hope, and have since renamed the conflicting folders and changed the PHP code. But if I can find a real solution to the problem, then I'd probably undo the changes and use it.

Unfortunately though, I don't really understand how your suggestion will resolve the problem.

Your rule says "if help does not exist as a directory, then apply the rule". But the problem is that help DOES exist as a directory, and I dont want that to impact the rewrite.

When the browser asks for http://host.bar.org/mywebsite/help, I want to load http://host.bar.org/mywebsite/main.php?menu=help (even though http://host.bar.org/mywebsite/help also exists as a real directory).

I also don't understand how somedir comes into it? What is somedir in your suggestion?
hawkmoon
 
Posts: 4
Joined: Fri Aug 12, 2005 1:21 pm

Postby seomike » Mon Nov 07, 2005 7:33 am

Mod rewrite isn't smart enough to decipher the two. You've got it to work by making one distinct (uppercasing one of the two). I'd leave it at that and call it a day :)
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 3 guests

cron