0

I want to pass parameters using $_GET but dont want to use the query form:

showevent.php?event=usa 

should be shown in the url instead want

site.com/events/usa

And for profiles:

site.com/username
2
  • 1
    workingwith.me.uk/articles/scripting/mod_rewrite Commented Jan 6, 2013 at 12:03
  • Do a web search for "php routing" - you'll find loads of libraries. I should think Zend, which is a library of loosely connected components, might have something to offer here. Maybe Symfony2 as well. Commented Jan 6, 2013 at 12:09

1 Answer 1

1

A browser does not know how to format URLs like that. The standard for submitting forms via GET is query strings and that's the only thing your browser can do. Two options:

  1. Build the URL via Javascript and redirect the browser programmatically. This has the drawback of requiring a Javascript-capable client.
  2. Submit via normal query strings, then on the server rewrite the URL and redirect the client. E.g.:

    header('Location: /events/' . $_GET['event']);
    exit;
    

    This has the drawback of requiring two roundtrips to the server each time and the not-rewritten URL may flash briefly in the user's browsers, but it gets you your nice URL in the end.

You may want a combination of both, with 2. being the fallback for non-Javascript clients.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.