Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule slash problem

         

Meander

12:47 am on May 19, 2009 (gmt 0)

10+ Year Member



I would like to have the www.website.com/index.php?id=value runnig after putting www.website.com/value/ or www.website.com/value in a browser. To do this I'm using the following code in .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/ index.php?id=$1

So now I can get the variable "id" through $_GET["id"]

The problem is that it doesn't work when I put www.website.com/value in a browser (without the trailing slash) - I get the "not founded on this server" error. I've tried several options but I'm still not able to make it running properly. Can anyone help me please? Thank you.

jdMorgan

2:24 am on May 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your pattern required the slash to be present.
Your rule would cause an 'infinite' rewrite loop, because the output URL-path matches the input pattern.

So, the pattern must be improved, and the looping must be explicitly prevented:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond $1 !^index\.php$
RewriteRule ^(.*)/?$ index.php?id=$1 [L]

See the resources cited in our Apache Forum Charter for more information.

Jim

Meander

7:36 pm on May 19, 2009 (gmt 0)

10+ Year Member



Finally, it works fine. Thank you!

g1smd

10:30 am on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Having provided 'what you wanted', are you aware that 'what you wanted' means that every page of your site now has at least three URLs that work - Duplicate Content?

You have 'with slash' and 'without slash' - I would add a 'slash' to 'without slash' redirect before the rewrite, and this redirect would also force the correct domain name.

You have 'dynamic' URL (yes, it still works!) and 'static' URL. You need a redirect for this too. Again, it is placed before the rewrite, and must force the correct domain name at the same time.

There are at least three steps needed to do the job properly. Currently you only have the third step.