1

My subject is different from the deprecated one, all I need is to get a string as URL without showing the PHP filename. I have items to click and to go to edit.php page I am trying to get a clicked string as URL.

e.g. if I click 'abc' , I want to go to the page edit.php and the browser displays :

http://localhost/abc 

not to

http://localhost/edit.php?item=abc

It's something like the routing in Symfony.

2
  • 2
    you need to use htaccess. Commented Oct 29, 2014 at 17:57
  • You may also need to include some kind of action in the url as well for example /edit/abc would take you to edit.php?item=abc while /abc might tack you to show.php?item=abc. In any event if you have more than a couple types of actions you are probably going to want to use a router on the PHP side instead of jsut htaccess only. Depending on how far along on your poject you are you might jsut want to use a micro framework like Silex or Slim. It will most likely save you time and headache. Commented Oct 29, 2014 at 18:02

1 Answer 1

3

Here is an example .htaccess file for your VERY SPECIFIC example above:

# turn on rewriting
RewriteEngine on

# check that the request isn't actually a real file (e.g. an image)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# redirect requests for BLAH to /edit.php?item=BLAH
RewriteRule ^(.*)$ /edit.php?item=$1 [NC,L]

Here are the docs you need for anything else http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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