0

I want to make a URL to look like this:

http://example.com/lobby/1

instead of

http://example.com/lobby.php?id=1

I know I can do this with .htaccess but I couldn't find a way how.

unor
  • 92,415
  • 26
  • 211
  • 360
Roy
  • 1
  • 4
  • Possible duplicate of [htaccess rewrite /book.php?id=1234 to /book/1234](http://stackoverflow.com/questions/11696718/htaccess-rewrite-book-phpid-1234-to-book-1234) – unor Mar 14 '16 at 11:19

3 Answers3

0

There are several already answered questions, such as .htaccess rewrite "/book.php?id=1234" to "/book/1234"

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^ lobby\.php$ /lobby/%1? [L]
Community
  • 1
  • 1
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
0

You can use the following :

 RewriteEngine on

RewriteCond %{THE_REQUEST} /lobby\.php\?id=([0-9]+)
RewriteRule ^ /lobby/%1? [NC,L,R]

RewriteRule ^lobby/([0-9]+)/?$ /lobby.php?id=$1 [NC,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • tried this, when i go to the lobby.php?id=1 it redirects me to lobby/1 but it says "404 not found". – Roy Mar 12 '16 at 11:38
  • @Roy is your htaccess located in root folder? – Amit Verma Mar 12 '16 at 11:41
  • its on the www folder with the rest of the files. @starkeen – Roy Mar 12 '16 at 11:41
  • Not Found The requested URL /lobby/1 was not found on this server. after updating – Roy Mar 12 '16 at 11:45
  • 1
    Perhaps Multiviews is on. Turn it off with `Options -Multiviews`. Truthfully, however, I am not sure if this is, in fact, the real issue here. – Mike Rockétt Mar 12 '16 at 12:10
  • @MikeRockett now i can see the page but i dont see the styling, all the css and js files are treated like its a folder. there is a way to fix it? – Roy Mar 12 '16 at 12:23
  • You need to reference front end assets relative to the root of your site. Just make sure each asset is referenced with a `/` at the beginning. Or set `` in your `` – Mike Rockétt Mar 12 '16 at 13:51
0

try this!

in htaccess file write this

RewriteEngine on

RewriteRule ^lobby/([0-9]+) lobby.php?id=$i

and in you html or php file call lobby.php?id=$i

page by

lobby/$i

you are done.

suraj
  • 326
  • 4
  • 6