0

Well I'm making profile pages so right now it looks like this

http://example.com/random/?user=Robert

What I want to do is remove ?user= from the URL so the page appears as

http://example.com/random/Robert

Iv'e searched and I can't find anything working for me. Thanks!

1
  • 1
    Use the term "clean urls .htaccess" in Google. Commented Aug 6, 2012 at 2:51

2 Answers 2

1

Based on http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html this should do the trick:

RewriteCond %{QUERY_STRING} ^user=(.*)$    [NC]
RewriteRule ^random$ random/$1             [NC,L,R=301]
Sign up to request clarification or add additional context in comments.

1 Comment

If you want to go the other way (as in making the URLs work as that in the first plas), there are plenty of samples around the interweb. Jon Lin's answer below covers that.
0

The first step is to make all of your links in this form http://example.com/random/Robert, then in the htaccess file in your document root, add:

RewriteEngine On
RewriteRule ^random/(.+)$ /random/?user=$1 [L]

But to handle 301 redirects to your old URLs, you can include this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /random/\?user=([^\ ]+)
RewriteRule ^random/$ /random/%1 [R=301,L]

5 Comments

It's not working, just getting a 404, typed and clicking a link.
@NardCake What excactly are you trying to accomplish? Getting the URLs to work (such that the user types /random/Username as an 'alias' for /random/?user=Username) or the other way around (rediredting /random/?user?Username to /random/Username)?
I'm trying to get it so users can type random/username.
@NardCake Are you sure mod_rewrite is enabled? And you have AllowOverride FileInfo (or All) allowing you do use things like mod_rewrite in htaccess files? Or that you don't have any other rewrite rules in your htaccess that has precidence?
@Jon Lin Well I'm using a host so i'm not sure, the only thing I have used it Deny from all to protect my source code. Is there a way to tell?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.