Forum Moderators: phranque

Message Too Old, No Replies

Creating friendly urls

how to remove '?' from links

         

hswaseer

2:18 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



hi guys

I am having problem creating friendly urls.Though i am able to remove .php extension from my file using apache forcetype through .htaccess file but i am facing problem of how to use the path_info

I want my url to look like this when moved to next stage

www.example.com/soccer/page1

but instead of this it is showing

www.example.com/soccer?id=1

My 2 files look like this.

code of .htaccess is as follows -

<Files soccer>
ForceType application/x-httpd-php
</Files>

code of soccer file is as follows

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

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

}
echo "<p> <a href=$PHP_SELF?id=1>1</a>
<p> <a href=$PHP_SELF?id=2>2</a>";

what should i do so that '?' is removed and it should look like

www.example.com/soccer/page1

Thanks for support and valuable time

HS

Longhaired Genius

3:08 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



What you have to do is write your code so it outputs the type of link you want eg,

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

THEN, you use .htaccess to rewrite these urls to a form that php will understand eg,
something like:

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

At least, that is the way I do it.

I don't think you need ForceType at all, because php is always sent as html.

Take it slowly and carefully and work on a test directory, not your live site.

hswaseer

8:07 am on Dec 29, 2003 (gmt 0)

10+ Year Member



Hi

Can you please elaborate more on this.

And can you send me the complete example code based on this topic .

Thanks

HS