Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite problem

         

hswaseer

11:36 am on Jan 14, 2004 (gmt 0)

10+ Year Member



Hi guys

I am making clean and friendly urls with help of mod_rewrite rule

I want the following url

http://www.example.com/testing/soccer.php?id=1

to change into this

http://www.example.com/testing/soccer/page1

The code of my .htaccess and soccer file is follows

CODE OF .HTTACCESS FILE

RewriteEngine On
RewriteRule ^soccer/([a-zA-Z]+)([0-9]+)/? soccer.php?id=$2 [L]

CODE OF MY SOCCER FILE

if($id==1)
{
echo "bla bla";
}

if($id==2)
{
echo "blee blee";
}

echo "<p> <a href=soccer/page1/>1</a>
<p> <a href=soccer/page2/>2</a>";

Though the code is working fine but you will see the problem in the url_window when you click on link '1' or link '2' two times. (It keeps on adding 'scoccer/page1' to url everytime)

How should i avoid this?
And secondly, is the code execution in the soccer file is ok

Thanks for help

HS

[edited by: jdMorgan at 6:15 pm (utc) on Jan. 14, 2004]
[edit reason] No site specifics, please [/edit]

Birdman

12:18 pm on Jan 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this rule will work better for you:

RewriteEngine On
RewriteRule ^soccer/page(.*)/$ /soccer.php?id=$1 [L]

You shouldn't need to use regex on the 'page' part, since you know it's there.

Added: I think the problem is due to the lack of a leading slash on the rewrite.