0

How do I rewrite this url:

www.website.com/index.php?gamename=GAME1

www.website.com/index.php?gamename=GAME2

to this:

www.website.com/GAME1

www.website.com/GAME2

It's going to be a dynamic website, fetching game names from the database via PHP. The php uses the gamename variable but I don't want that to be seen by visitors.

I'm new to all of this, so if my descriptions are different I hope you know what I mean.

Looking forward to replies, Thanks

EDIT: Some suggestions mentioned, still don't do what I'm needing done. I need to remove everything after / Except for the gamename

Anth23
  • 1
  • 1
  • 1
    Possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Nytrix Jan 19 '17 at 20:28
  • I think [this link](http://stackoverflow.com/questions/36332977/need-to-rename-the-url-using-htaccess) might help answer your question. – Robotnicka Jan 19 '17 at 20:28
  • Also, as you state that you are all new to this. Please be sure to use `PDO` and `Mysqli` in your application, often `mysql_*` gets used as a lot of old tutorials use it, please don't. In future questions, try **google** first, then ask the question. If you *do* have a valid question, provide a [mcve] – Nytrix Jan 19 '17 at 20:30
  • Try google, I've tried for 2 weeks before asking a question – Anth23 Jan 19 '17 at 20:32

1 Answers1

0

You can use this:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?gamename=$1 [L]

It will work for both URLs; make sure you clear your cache before testing it.

Joe
  • 4,877
  • 5
  • 30
  • 51
  • Tried this and it doesn't work, the game name within my page changes to index.php and the url stayed the same – Anth23 Jan 19 '17 at 20:49
  • I tested this and it worked. Do you have other items in your `.htaccess` file could conflict with this rule? – Joe Jan 19 '17 at 20:52
  • I removed everything to try your suggestion. Does my php code conflict then? – Anth23 Jan 19 '17 at 20:56