Welcome to WebmasterWorld Guest from 34.204.168.57

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Newbies rewrite problem

Help required for mod_rewrite

     
5:42 am on Sep 4, 2005 (gmt 0)

New User

10+ Year Member

joined:June 28, 2005
posts:8
votes: 0


I want to change my url from

www.domain.com/userprofile.php?username=bill

to

www.domain.com/userprofile/bill.htm

Please tell what I have to write in my htaccess file

Help needed.

5:45 am on Sept 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 9, 2005
posts:1509
votes: 0


Hi ashokarorain,

Welcome to WebmasterWorld.

The best place to start is in the library, and then the charter (links at the top left of the pages). That should get you going, then when you have something you have tried we will help you make it work.

You are basically going the wrong way... should link to the friendly URL then rewrite the information from the dynamic one to that.

Justin

5:50 am on Sept 4, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Apr 21, 2004
posts:306
votes: 0


I think this might do the trick:

RewriteEngine on

RewriteRule ^userprofile/(.+)\.htm$ h++p://www.domain.com/userprofile.php?username=$1 [L]

Note that the [L] is on the same line, just one space between it and the $1.

Depending on valid characters for usernames, you could make this more efficient. If lowercase a-z are the only valid characters, then replacing (.+) with ([a-z]+) would be more efficient. Also note that the ++'s should be t's in the URL; I changed them out so it wouldn't turn it into a link on the forum.

12:55 pm on Sept 4, 2005 (gmt 0)

New User

10+ Year Member

joined:June 28, 2005
posts:8
votes: 0


Thanks roldar for the solution. It worked fine, however I have to changed the path of all relative links because they were pointing to different directory