Log in

View Full Version : Resolved index w/o extension confusing query string with directory



JShor
08-28-2009, 04:08 PM
Hi,

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:

http://mysite.com/index/MyQueryString

That works just fine for me. However, if I try this:

http://mysite.com/MyQueryString

... 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.

Like:
http://facebook.com/username
http://youtube.com/username

Thanks in advance for all responses. :)

JasonDFR
08-29-2009, 06:52 AM
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.