...

View Full Version : How do websites that use no extensions work?



MJBoa
05-18-2008, 11:02 PM
For example, http://www.last.fm/users/. I never see any file extensions on that site... I don't even know if it's in php but how does it work? And how would I even figure out how it's programmed?

peteyb383
05-18-2008, 11:14 PM
What is happening there is that you are really on a page called "index.php" or something like that, because in their hosting account they have sent the automatic default page to be "index.php" or something similar.

In other words, they can send you to a directory without a specific file, but the default file manager automatically allows their default page to be pointed to.

Just like when you go to almost any domain, it typically wont be http://www.thesite.com/index.php ... rather, it will just be http://www.thesite.com/ without an extension.

LAMPE
05-19-2008, 12:09 AM
They have modified their .htaccess and did a mod_rewrite

MJBoa
05-19-2008, 12:18 AM
Would mod_rewrite allow them to have something like http://www.last.fm/user/MJBoa? They obviously don't have a page called MJBoa.php or something and I assume there aren't thousands of directories with user names so how does it interpret that into someone's username?

bazz
05-19-2008, 12:21 AM
Likely, you'll find that www.last.fm/user/MJBoa isn't just a url. Probably, the url is www.last.fm/user and the 'MJBOa' is part of the path sent to the php file at /user telling it whose data to display, presumably, from a Db.

bazz.

MJBoa
05-19-2008, 12:29 AM
I was thinking that there might be an index.php in user/ that responds to something like user/MJBoa but how does it know to load index.php and not the MJBoa directory? I'm trying to figure this out so I can implement something similar, thanks for the help.

dniwebdesign
05-19-2008, 01:24 AM
You can use .htaccess to do just this. I have a website I am currently constructing something simlar for user profile pages where it is http://mywebsite.ca/username takes it to a user page.

What the .htaccess does is takes it and shows a page which is really http://www.website.ca/profile.php?user=username but the site looks like I said above.

In fact I asked a similar question here: http://www.codingforums.com/showthread.php?t=125802

bazz
05-19-2008, 12:00 PM
If you have access to the server, you don't need to make any htaccess changes.

Simple set the server to show index.php by default. All my isp's, when on a shared platform had the server set up taht way. When I moved to my own dedicated server, that was the default setting and when I wanted to change from showing index.htm by default, to showing index.shtml, it took only one phone call.

Maybe that would be your easiest way?

bazz

runnerjp
05-19-2008, 03:46 PM
here you go i poped something together quickly for you..

ok htaccess


RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^([^/.]+)/?$ lastfm/users.php?page=profile&username=$1

ok so as you can see the page = profile.. so profile.php in this case so it pulled up profile.php and username is the username you have typed into the url so www.last.fm/user/MJBoa well bring up MJBoa's profile

of course there is more to it then that because you need to pull the information from the db for username but its really easy... hope that helps explain a little more

syosoft
05-19-2008, 03:49 PM
.htaccess is by far the cleanest way, but it does introduce a layer of abstraction. You can always set your sites 404 page to be index.php and then deal w/ the conditions there - thou i wouldnt recommend it for anything more than proof of concept.

abduraooft
05-19-2008, 03:52 PM
syosoft, can we post data from a form to index.php, if we follow such an ErrorDocument rule?

syosoft
05-19-2008, 04:00 PM
Sure, apache would route every non existing page to 404 (index.php), post and all - again, i'm not really suggesting this method. If you have the ability to use .htaccess, dont let ModRewrite scare you - it is an extremely powerful tool.

I'd rather see you use a design pattern similar to what i recently wrote up. See http://www.codingforums.com/showthread.php?t=139974

abduraooft
05-19-2008, 04:16 PM
I had been using
ErrorDocument 404 /index.php and then use $_SERVER['REQUEST_URI'] to decide which pages are to be included in to index.php. (All my links are of the form /home, /about etc)

But then I realised that external data is not getting passed to index.php. So, I've added
RewriteRule ^([^/\.]+)$ index.php [L] also in to my htaccess and found everything OK.

syosoft
05-19-2008, 04:20 PM
Ok - good to point out. I was apparently wrong about $_POST data coming along as a result of ErrorDocument.

You might want to change that to [QSA,L] so the querystring comes along as well.

abduraooft
05-19-2008, 04:38 PM
sysoft, but where to add that condition, in my above case?

aedrin
05-19-2008, 05:08 PM
Sure, apache would route every non existing page to 404 (index.php), post and all - again, i'm not really suggesting this method. If you have the ability to use .htaccess, dont let ModRewrite scare you - it is an extremely powerful tool.

I'd rather see you use a design pattern similar to what i recently wrote up. See http://www.codingforums.com/showthread.php?t=139974

It probably shouldn't even be suggested for how bad this solution is (the 404 method).

abduraooft
05-19-2008, 09:12 PM
It probably shouldn't even be suggested for how bad this solution is (the 404 method).
aedrin, could you please let me know the error/problem in the above method?
(Initially I had been using an index.php?page=?something method, and then I changed to a userfriendly way like /something and used some htaccess to instruct the server.
But it was not easy for me to catch and redirect all requests to the index.php page, say /something/someother as server was still getting a valid value to the page variable. And so for /something/someother/andmore also. )

But, I haven't seen any such problems for the above posted method, (by me, just 2 post above)

aedrin
05-19-2008, 10:01 PM
Because the 404 document should not be reached unless there really is a 'could not find your document' issue. It might also mess up the server logs (as it'd show 404).

Either way, the alternatives are perfectly fine solutions. There is nothing wrong with using ModRewrite, and is probably the cleanest/most effective method.


But it was not easy for me to catch and redirect all requests to the index.php page, say /something/someother as server was still getting a valid value to the page variable. And so for /something/someother/andmore also.

Don't write them out specifically, use a wildcard filter to catch specific requests.

If you search on this forum, or look at google. One of the ways to prevent everything from going through the filter (including images/css/js/etc.) is to add a RewriteCond to ensure that they are not real files and/or directories. I believe the flag is -d and -f, but you will have to look for the complete syntax.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum