File Extensions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

File Extensions

Post by thesimon »

Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

There is no more 'professional' way, it's like asking which is more professional, print, or echo?
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

Post by thesimon »

True, very true.

But I suppose the most obvious question is, which do you prefer? What do you use?

Besides, if i use echo or print, the end user will not see any difference.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Apparently people (and the webserver) seem to like/handle files differently based on the ending of their name.. But without really verifying the content of the file (no prejudices allowed) you don't know for sure... Well, Microsoft thinks differently, and that explains why you can do .exe.gif tricks :D

So, apart from technical reasons (it's silly to pass each plain html file to the php parser) it's all subjective. (I believe in good content and not companies that try to sell SEO BS)

I've seen people that choked if you give them an URL without a www at the beginning.. I think it easier to remember example.com/contact than example.com/contact.php or example.com/contact.asp... But the most usable (imho) is to surf to example.com and click on the "contact" button...


The difference between print and echo is explained in the manual ;)
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

thesimon wrote:True, very true.

But I suppose the most obvious question is, which do you prefer? What do you use?
Ah, well I prefer just using file.php, but if it's a complex site, I use mod_rewrite to turn urls into "www.site.com/contactus/1/3"
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I read once that doing it without the *.php extensions helps if you ever decide to move technologies: no bookmarks break, and it's transparent to the user.

That being said, implementing this well will require a bit of Apache hacking, so if you're on shared hosting, it's probably not a good idea.

Google uses search?q=bang note how it still uses GET variables, it just zapped the extension. That's how I suppose I would do it.
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

Post by thesimon »

Is there any easy way to "zap" the .php using the .htaccess. I am on reseller hosting, so i do not have much control.

Thankyou for your help so far, this is very interesting.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

It's mod_rewrite, I'm sure. Unfortunantely, I'm not well versed in the "Voodoo" comparable to "sendmail", so I can't help you.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: File Extensions

Post by Roja »

thesimon wrote:Whats the most professional way when it comes to page extensions and url passing?
Ambush hit the nail on the head: Leave off the .php!

From W3c's "cool uri's" page:
File name extension. This is a very common one. "cgi", even ".html" is something which will change. You may not be using HTML for that page in 20 years time, but you might want today's links to it to still be valid.
As to how? Its easy. By default, Apache will do content scanning. In other words, if there is no extension, it goes through a list to find a good match. If you said, http://www.example.com/something , then it would look in the /public_html dir for:

something.html
something.php
etc

If there is only one match (ideally), thats the one it will use. No hacking required. IIS acts similarly. The only requirement for both is that the webserver must be aware of PHP (.php) as a content type.

Easy!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You're right! That's pretty awesome! Although those interested in saving their CPU from a few extra cycles should use mod_rewrite just to make sure Apache knows exactly where to look.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Ambush Commander wrote:You're right! That's pretty awesome! Although those interested in saving their CPU from a few extra cycles should use mod_rewrite just to make sure Apache knows exactly where to look.
Actually, if there is only one choice in the directory, mod_rewrite will use more cpu cycles. :)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

That is true.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

You don't have to use mod_rewrite, you can also just use the ForceType directive, normally much easier....
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

There certainly is a wrong way and that is using a query string to serve static pages. It is similar to using tables fo layout, it is wrong but you see it everywhere on the web.

For me the most professional way is any way that is easy for the viewer. So 'cats.com/pedigree/persian' is a lot easier than 'www.cats.com/index.php?type=pedigree&breed=persian'. If anyone prefers typing the second one please see a psychiatrist!
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

My preferred way (and how I'm slowly converting most of my sites) is the
host.domain/scriptname/var1/var2/var3

style, where var1..3 are things that define a page. (Like the cats.com/pedigree/persian/ example above)

This still looks "friendly" to me. The end user can tell exactly where a mailed/bookmarked link will be going and have to try to remember a long string of "gobblygook".

If something truly is a form then GET/POST can still be used, but "templated pages" should be given nice URLs.

I don't like overloading a single scriptname with too much extra stuff, so I try to keep them very focuses (not the one page serves an entire site model).

I often submit forms to an "interstitual" page that then redirects where needed. Most such scripts will end up in a subdirectoty named SCRIPTS for me; these still have an extension but only visible to the user briefly in the location bar before the redirect (only under high server load, too).
Post Reply