without getting the query string, just getting the page directory or file. I’m not talking about PHP_SELF because that doesn’t work if the URL needs to be displayed as:
that would be okay, but it needs to be suitable for either scenario, showing either the directory or page, but not the directory AND page, and definitely NO query string.
What about website.com/dir/contact.php?
Are you using mod_rewrite?
What url are you actually having problems with? If you want to ignore index.* then you will have to make it a special case.
Do any of the request parameters actually have an effect on the page?
It would be oh so simple if it were just a single page, but the purpose is to dynamically and cleanly collect ANY URL, but it’s not meant to actually rewrite the page/browser URL.
and in many cases is very good about presenting a clean URL to display already, even removes # and everything after, but if there’s a query ? or & it goes on ahead and adds it anyways, I know that’s how REQUEST_URI is programmed to work, but I just find it awfully annoying and out of place that it does that because there’s already REQUEST_QUERY or something similar for that purpose.
So I’ve been wracking my brain the last few days trying to kill the query string from being displayed with the URL, again this isn’t a .htaccess thing because I don’t want to manipulate the actual page URL, but collect it and clean it for other display purposes. It always seems like the simplest task is always the hardest one.
I know there must be a way, there is always a way.
with the top line being for adding exceptions, pages you don’t want to remove query strings from, but again, we’re not talking about .htaccess or rewriting the actual page URL.
@logic_earth
You’re definitely on the right track my friend, but maybe you can help me with the syntax. Because, the context in which I need the code presented throw errors when using ():
There is no specific problem, I just need to create clean URLs dynamically, dynamic being the key word. I simply need to strip queries off URLs, there must be a way in PHP to say if ? is found, remove it and everything after it…
There’s no other way I can say it or put it, I’m sure there’s someone that’s run into this before and has an answer, no worries though, I don’t want anyone to put too much time into this, if you have the answer superb, if not please don’t waste any more time on it.
Logic_earth has your answer, I am/was confused as mod_rewrite can screw with your query string. With plain file access and a query string, you get this:
I’m not sure why SELF or SCRIPT isn’t enough, but you can str_replace the query in the uri and trim the ?
Don’t worry about people wasting time, it’s theirs to waste I just think you need to post some concrete examples.
Edit, I’m also assuming you want to do this for canonicial URLs, rather than pretty URLs? That is, you want to remove unnecessary tracking etc from a url to prevent duplicates rather than just make it look nice.