Welcome to WebmasterWorld Guest from 107.22.86.42

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Fake Directory Mod_rewrite problem with slashes

Mod_rewrite question

     

pjmaenh

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

Inactive Member
Account Expired

 
 


Hi,

i have this problem:
like most people, i want to get my server so that
[domain.com...]
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
posts:25430
votes: 0


pjmaenh,

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].

Jim

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

Full Member

10+ Year Member

joined:Dec 25, 2003
posts:269
votes: 0


There's an easier way:

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


index.php:
<?php
$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.