0

I need some help. Whenever I am making a PHP get request, say for name, how would I change this: http://website.com/page?name=Something

to this: http://website.com/page/Something

Thanks for your time!

MineStein
  • 1
  • 1
  • 2
    you need to use something like apache mod_rewrite to rewrite the url to script. search for that and you will find a ton of examples – Doon Dec 30 '14 at 17:16
  • It is called URL rewriting. Possible duplicate of [this question](http://stackoverflow.com/questions/16388959/url-rewriting-with-php). – Crackertastic Dec 30 '14 at 17:19
  • @Doon You don’t necessarily need URL rewriting techniques, something like Apache’s *MultiViews* and *path info* would suffice. – Gumbo Dec 30 '14 at 17:22

2 Answers2

1

Use htaccess

RewriteEngine on
RewriteBase /
RewriteRule page/([0-9a-zA-Z]+)/ page?name=$1
SSRaavi
  • 16
  • 7
0

What you want is to be able to route requests. It depends on how your application receive requests

If you're using apache with mod_php, the routing corresponds to your filesystem (path in the request → path of the file). This is a very bad form of routing, and confuses a lot of beginners, because you have basically no power on how the requests are handled. Your best solution is to use Apache URL Rewriting, which will allow you to transform /page/something into /page?name=something so that it can be handled properly by mod_php.

If you have more control on your httpd, you should try some PHP routing libraries like https://github.com/chriso/klein.php or http://zaphpa.org/ that will give you a better control on how your requests are dispatched.

Antoine Pietri
  • 793
  • 1
  • 10
  • 25