Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Fake Directory Mod_rewrite problem with slashes

Mod_rewrite question



8:50 pm on Jan 18, 2004 (gmt 0)

Inactive Member
Account Expired



i have this problem:
like most people, i want to get my server so that
Goes to [domain.com...]
I tried this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^([^/]+)/$ index.php?menu=$1 [L]

This only works fine when I add a / behind item:
[domain.com...] works,
but I want [domain.com...] to work too.
How can I do this?

10:07 pm on Jan 18, 2004 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
votes: 0


Welcome to WebmasterWorld [webmasterworld.com]!

You can make the trailing slash optional by following it with "?"

RewriteRule ^([^/]+)/?$ index.php?menu=$1 [L]

Ref: Regular Expressions tutorial [etext.lib.virginia.edu].


10:54 pm on Jan 18, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Dec 25, 2003
votes: 0

There's an easier way:

RewriteRule ^(\.*)$ index.php [L]

$uri = explode("/", $_SYSTEM['REQUEST_URI']);
$menu = $uri[1];

Mind you, I don't have much experience with this, so I might have made an error, but the basic idea is correct.