pokonipo Posted December 6, 2007 Share Posted December 6, 2007 I want to have a PHP script that will remove the query string from a URL when the server sends the page to the user. I want the script to work regardless of how short or how long (or existent or nonexistent) the query string might be. So, for example, if the user types any of these URLs into the address bar of their browser... http://example.com/page.php http://example.com/page.php? http://example.com/page.php?a http://example.com/page.php?a= http://example.com/page.php?a=b http://example.com/page.php?anything=anything&etcetera=etcetera ...this URL will appear in the address bar of their browser when the server sends the page to the user: http://example.com/page.php Thanks in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/ Share on other sites More sharing options...
Stooney Posted December 6, 2007 Share Posted December 6, 2007 You're looking for mod_rewrite http://www.sitepoint.com/article/guide-url-rewriting Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-407683 Share on other sites More sharing options...
~n[EO]n~ Posted December 6, 2007 Share Posted December 6, 2007 There are tons of examples here too... http://www.phpfreaks.com/forums/index.php/board,50.0.html Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-407684 Share on other sites More sharing options...
pokonipo Posted December 6, 2007 Author Share Posted December 6, 2007 That info about mod_rewrite is interesting, and I thank you for it. But it does not directly apply to my original post. Notice that I said this in my original post: "I want to have a PHP script..." Mod_rewrite is not a PHP methodology. Please post the code for a PHP script that will accomplish what I described in my my original post. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-407700 Share on other sites More sharing options...
~n[EO]n~ Posted December 6, 2007 Share Posted December 6, 2007 I don't think it can be done through PHP, best solution is mod_rewrite. I think this kind of question has been asked lot of times.. you can search this forum. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-407705 Share on other sites More sharing options...
pokonipo Posted October 19, 2008 Author Share Posted October 19, 2008 I am re-opening this thread several months after I started it because I have now finally discovered that there is a PHP solution to what I wrote about in my OP (in spite of the fact that all of the responses to my OP seemed to imply that there is no PHP solution). Here is the PHP solution: <script language="php"> if($_get){header("location: http://example.com/page.php");} </script> blah blah blah By the way, make sure there is no content (not even white space) above that PHP code. Put all content below it. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-669163 Share on other sites More sharing options...
zoonose Posted October 19, 2008 Share Posted October 19, 2008 Essentially... you were asking the wrong question. You should have asked for a 'redirect'. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-669167 Share on other sites More sharing options...
pokonipo Posted October 19, 2008 Author Share Posted October 19, 2008 Zoonose: what you are essentially saying is that I should have known the solution to my problem before I asked for a solution. That's ridiculous. How was I supposed to ask for a 'redirect' when I had absolutely no idea what the solution was to my problem?! Contrary to Zoonose's view of it, anybody who scrolls to the top of this page can see that my OP was very clearly worded. Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-669175 Share on other sites More sharing options...
dropfaith Posted October 19, 2008 Share Posted October 19, 2008 <?php if (!isset($_GET)) { header('Location:http://example.com/page.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-669195 Share on other sites More sharing options...
pokonipo Posted October 20, 2008 Author Share Posted October 20, 2008 Woops! I used the wrong case in certain parts of the code that I posted above. Here is the correct code: <script language="php"> if($_GET){header("Location: http://example.com/page.php");} </script> blah blah blah Quote Link to comment https://forums.phpfreaks.com/topic/80406-remove-query-string/#findComment-669860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.