index w/o extension confusing query string with directory
No code is necessary to explain this dilemma. What I've done is I've set my .htaccess file to allow PHP script files to have the option of NOT having the .php extension.
Now, I want the index file to determine query strings, like so:
That works just fine for me. However, if I try this:
... it is recognized as a directory on the server. Is there any way I can get around this? It seems that sites such as youtube and facebook are able to do this.
Thanks in advance for all responses.
Last edited by JShor; 09-02-2009 at 04:13 PM.
I don't have any experience with removing file extensions, so I can't speak to that, but I can tell you that this is not what facebook and youtube are doing.
Facebook and youtube and many other sites use mod-rewrite or an equivalent to send all requests to one file, usually the "index" file in the site's document root.
From there the url is parsed and the relevant page is returned.
So, www.facebook.com/username is actually being sent to "index.php" where it is determined that the request is for the "username" page.
As for your query string example, if you change nothing at all in .htaccess (or don't even have a .htaccess file) and go to http://mysite.com/index/MyQueryString, you will see your site's "index.php". MyQueryString does not get put into the $_GET array. However, if you replace "index" with anything else, a directory is looked for and you'll get the 404.
So what you are explaining is "default" behavior. I don't think anything you have changed in .htaccess is causing it.
If you are able to access 'MyQueryString' in your http://mysite.com/index/MyQueryString url, I'd be interested to know how you are doing it. Unless you are parsing the whole URL, I don't think that 'MyQueryString' will exist in the $_GET array. Let me know.
The Following User Says Thank You to JasonDFR For This Useful Post: