How to change this to friendly url?

Discuss practical ways rearrange URLs using mod_rewrite.

How to change this to friendly url?

Postby celebritywallpaper.us » Tue Feb 03, 2009 12:00 pm

Hello

How do i change this to a friendly url
http://www.mydomain.co/file.php?f=1024&a=popup


how do i make the above look like this
http://www.mydomain.co/play/hello-world.html


i think something like this but i am not sure
RewriteRule ^play/(.*).html file.php?f=$1&a=popup


Thanks advance
celebritywallpaper.us
 
Posts: 41
Joined: Sat Feb 03, 2007 6:27 am

Postby richardk » Tue Feb 03, 2009 12:04 pm

FAQ: How to change a numeric ID into a name/title.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^play/(.+)\.html$ /file.php?a=popup&name/title=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby celebritywallpaper.us » Tue Feb 03, 2009 3:32 pm

i change stuffs around and i got this to work
Code: Select all
RewriteRule ^play-([0-9]+)/(.*).html file.php?f=$1&a=popup


However its dont have a dash between space
so the url look like this www.mydomain.com/play-2121/hell world.html

how do i change to hell-world?

Thanks
celebritywallpaper.us
 
Posts: 41
Joined: Sat Feb 03, 2007 6:27 am

Postby richardk » Wed Feb 04, 2009 11:43 am

how do i change to hell-world?

You have to change the code that outputs the link. It is not something mod_rewrite can do.

You should be using the L flag, escaping literal "."s and using $ to match the end of the URL
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^play-([0-9]+)/(.+)\.html$ /file.php?f=$1&a=popup [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 23 guests

cron