-5

Possible Duplicate:
How to: URL re-writing in PHP?

There are many examples of my question online but since it involves some RegEx I could use a little help from you.

How can I convert this URL....

www.example.com/profile.php?user=username123

...into this URL?

www.example.com/username123
Community
  • 1
  • 1
suchislife
  • 4,251
  • 10
  • 47
  • 78
  • In that form, this question has been asked and answered already. Unless you do not show what you've tried so far and explained per given examples what did not work in *your* case because of what it is different, I do not have much motivation to help. Just saying. – hakre Nov 25 '12 at 20:23
  • Alright. I'll make it sound way more complicated than it is while at the same time coming to the same conclusion which is. I do not understand MOD REWRITE or REGEX. I'll be back to copy and paste some examples I've found which will give the illusion of research while I remain clueless as to how it works. – suchislife Nov 25 '12 at 20:25
  • It's just that to understand regex, you need to learn. Start with something simple. Regular expressions are a sort of language on it's own with their own rules. When I started with mod_rewrite years back, I normally used the (that time apache 1.x) documentation. They have a list of examples what you can do with mod_rewrite and how. – hakre Nov 25 '12 at 20:27
  • Sarcasm is the lowest form of wit. Instead, why not put your efforts into helping the people trying to help you, or doing (trivial) research? – Bojangles Nov 25 '12 at 20:27
  • It seems easier to understand women than regex. – suchislife Nov 25 '12 at 20:28
  • 2
    Oh gosh. You are so male or what? Sorry, but this is getting out of hands. – hakre Nov 25 '12 at 20:28
  • "Regular expressions are a sort of language on it's own with their own rules." Come on, what else fits this description to a T? ;) – suchislife Nov 25 '12 at 20:34

1 Answers1

1

Create a file called .htaccess in your root folder and write the following in it.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ profile.php?user=$1 [QSA,L]
samayo
  • 16,163
  • 12
  • 91
  • 106
  • if my root folder already contains one, can i place this code anywhere in it or somewhere specifically? – suchislife Nov 25 '12 at 20:32
  • Do you mean in your root you have already an .htaccess file? – samayo Nov 25 '12 at 20:37
  • yeah it's in my root. it has so default mod rewrite roles but not like yours. – suchislife Nov 25 '12 at 20:39
  • Well add `RewriteRule ^(.*)$ profile.php?user=$1 [QSA,L]` after the last line and see what happens – samayo Nov 25 '12 at 20:40
  • It did not. when I type www.mysite.com/vini it does not retrieve the contents of www.mysite.com/profile.php?user=vini I get a 404 page not found isntead. – suchislife Nov 25 '12 at 20:51
  • Then try deleting everything that was in your .htaccess file and replace it all with my previous code. – samayo Nov 25 '12 at 20:52
  • Internal server error when I do that. – suchislife Nov 25 '12 at 20:59
  • well I am using the same code to redirect a user from `site.com/index.php` to display `site.com\user` in the middle there is a `profile.php?user=user` the problem could be from your apache. If you want to learn about url-rewrite thought, this is s great tutorial: http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/?searched=url&advsearch=oneword&highlight=ajaxSearch_highlight+ajaxSearch_highlight1 – samayo Nov 25 '12 at 21:08
  • i'm using the htaccess file that came with http://html5boilerplate.com/ also using WAMP. – suchislife Nov 25 '12 at 21:19
  • Well my site is costume built, and it is easier that way to debug. – samayo Nov 25 '12 at 21:50