views:

20

answers:

2

I'd like to strip a URL of it's query string using mod_rewrite but retain the values of the querystring, for example, id like to change:

http://new.app/index.php?lorem=1&ipsum=2

to a nice clean:

http://new.app/

but retain the values of lorem and ipsum, so inside index.php:

$_GET["lorem"]

would still return 1 etc.

This is my first dabble with mod_rewrite so any help is greatly appreciated, and if you could explain exactly how your solution works, I can learn a little for next time too!

Thanks!

A: 

I don't understand exactly what you want. Your first URL is the external form, which the users see and can type into their browsers.

The second form has almost all information stripped, so when you send that to a server, how is the server supposed to know that lorem=1&ipsum=2?

If your question is really

How do I make the URLs in the browser look nice, even if the user is somewhere deep in the website clicking on URLs that carry lots of information?

then there are two solutions:

  1. You can pass the information in small bits to the server and save them all in a session. I don't like that because then the user cannot take the URL, show it to a friend and have him see the same page.
  2. You can have your entire web site in an HTML <frameset> containing only one <frame>. That way, the URL of the top-level window will not change, only the inner URL (which is not displayed by the browser) will.
Roland Illig
A: 

As Roland mentioned, you don't seem to understand the way rewriting works. It's typically done using Apache mod_rewrite in .htaccess, which silently rewrites the pretty URLs to the php script as /index.php?lorem=1&ipsum=2

Even Joomla uses .htaccess, except it has a single rewrite rule that passes EVERYTHING to a PHP script which does the actual rewriting in PHP.

What you are not understanding is that something still needs to exist in the "pretty" version for the php script to pull the value of $_GET["lorem"]

So it would be like http://new.app/lorem/ or http://new.app/section/lorem which would then (using mod_rewrite in .htaccess) rewrite TO the php script.

degenerate