Forum Moderators: phranque

Message Too Old, No Replies

Newbies rewrite problem

Help required for mod_rewrite

         

ashokarorain

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

10+ Year Member



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.

jd01

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

WebmasterWorld Senior Member 10+ Year Member



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

roldar

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

10+ Year Member



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.

ashokarorain

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

10+ Year Member



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