0

Hi everyone, I have a website that gives me the following url when viewing a users profile.

website.com/index.php?a=profile&u=username

I am trying to create a htaccess rule that will generate a friendly url like
website.com/username

The existing htaccess file is

RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$  index.php?a=$1&u=$3    [L]

Thanks in advance...

Edited by JorgeM: Moved to a more appropriate category.

3
Contributors
9
Replies
25
Views
4 Years
Discussion Span
Last Post by mmcdonald
0

To make:

**The original URL:**
http://website.com/index.php?a=profile&u=username

**The rewritten URL:**
http://website.com/a/profile/u/username.html

**Use:**
RewriteEngine On
RewriteRule ^a/([^/]*)/u/([^/]*)\.html$ /index.php?a=$1&u=$2 [L]

To make:

**The original URL:**
http://website.com/index.php?a=profile&u=username

**The rewritten URL:**
http://website.com/profile/username.php

**Use:**
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.php$ /index.php?a=$1&u=$2 [L]

Edited by mmcdonald

0

The first rule sample that mmcdonald provide is accurate. I quicly tested it myself even though it looked accurate.

My experience with rewriting questions is that some people seem to be confused about the process... For example... if you type this in the URL:

http://website.com/index.php?a=profile&u=username,

That will not be redirected to http://website.com/profile/username

URL rewriting works in that it takes the friendly URL so the visitor doesnt have to see or know the actual page or parameters.

So, your user will type this URL: http://website.com/profile/username

You take care of the backend process of getting the correct page and parameters processed.

Edited by JorgeM

0

Thanks for testing and feeding back your results JorgeM. Explaining URL rewriting was a smart move.

Michael

0

Thanks gents, very much appreciated, I will have a look through the website too see if I can find any other rules.

I am helping a friend out who had the website designed by a freelancer, who has suddenly gone missing after being paid.

0

That's nothing new Everton, I always use something like Escrow when dealing with Freelancers - but I'm sorry to hear it.

The above rewrite will work, perhaps it's being implemented incorrectly? It's been tested by JorgeM and he's a seasoned programmer.

Either way, good luck!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.