homepage Welcome to WebmasterWorld Guest from 54.234.60.133
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Should I use .php extension or .htaccess
Vespasian




msg:4114120
 5:22 am on Apr 12, 2010 (gmt 0)

I'm making a web site from scratch. Each page will have .php includes.

Would it be better to name each file with a .php extension? Such as index.php. Or, would it be better to name each file with an .html extension - such as index.html - and then run the php includes by putting the following line in my .htaccess file - AddType application/x-httpd-php .php .htm .html .shtml

Or, maybe it doesn't make any difference either way. This is a brand new site that has not yet been indexed by the search engines. So, I could go either way. But I don't have expertise in this. Any suggestions?

 

Matthew1980




msg:4114155
 7:31 am on Apr 12, 2010 (gmt 0)

Hi there Vespasian,

For my understanding of using .htaccess/mod_rewrite it is easier to keep the .php extensions and re-write the extensions that way. I do it for all of my projects and as far as I can tell it makes the pages more URL friendly/search engine friendly & there is no discernable difference on page loading times from what I can tell either.

I find this particularly useful if you pass a lot of information through the URL, makes it tidier and the search engines index it quicker too, at least this is how it seems to me.

From .htaccess tweaks you can do all sorts of cool stuff, my particular favorite is prevention of directory browsing, and with a few php coding tweaks you can prevent someone from opening a file directly if they try to access a file directly.

If you are running ANY php from a file, call it .php this tells the parser what to expect, though I have learnt recently that you can tell the server different, but to me that seems a bit convoluted, and kinda bad practice.

I hope I understood you correctly ;-p

Cheers,
MRb

Vespasian




msg:4114163
 7:44 am on Apr 12, 2010 (gmt 0)

Thanks. That was my initial inclination. I named the files with .php extensions. I'm new to php includes and I am building about 20 of them on each page. Do you think that will cause me a problem with that many? I anticipate eventually having more than 100,000 unique visitors per day (always the optimist)...

Matthew1980




msg:4114179
 8:44 am on Apr 12, 2010 (gmt 0)

Hi there Vespasian,

Shouldn't make a difference... I use them all over the place, primarily to reduce the amount of repetition in code :)

No harm being an optomist either ;-p

Good luck,

Cheers,
MRb

jdMorgan




msg:4114509
 7:07 pm on Apr 12, 2010 (gmt 0)

One thing to note is that URLs and filenames are completely-different things. They are "associated" only by the action of your server. Therefore, there is no reason that your "pages" need to have either .php or .html in their URLs. The file extensions only have meaning inside the server's filesystem.

A fairly-strong recent trend is to use extensionless URLs for your pages, and then rewrite them to the appropriate filetype(s) -- or use various other server mechanisms to do so.

This results in short, pretty, and easier-to-remember-and-cite URLs, like "example.com/shop"

It also prevents you from "exposing" your site's technology in your URLs -- Not a great concern security-wise, but potentially a real pain if you decide to change it.

Anyway, if this sound appealing to you, now is the time to decide -- before publishing your first pages.

Jim

Matthew1980




msg:4114580
 8:28 pm on Apr 12, 2010 (gmt 0)

Hi there jdMorgan,

It also prevents you from "exposing" your site's technology in your URLs


This was one of the main reasons I decided to go 'friendly URLs' about a year ago, and I must say that it is alot easier to code - once you get the hang of it.

Part of the rewrite module is that you can "change" on the fly what the browser shows in the address bar from what is actually served from the server ie from index.php -> index.html, this is a way of covering up the technology you are using (which is why I quoted it)

Aside from that you can take an url with parameters/value in and turn them into path/to/your/files/index.html and this is just to give the appearance of a directory structure, whereas you may have something like :-

index.php?request=page&id=10&subcat=10&item=1

turned into:-

/id/10/subcat/10/item/1/index.html

You get the jist.

But as you point out, these style URL's have become more popular in the last few years, as people wish to be a bit more security minded & are cautious of what to do and how to take precautions.


Anyway, if this sound appealing to you, now is the time to decide -- before publishing your first pages.


Agreed, as changing your mind just before completion would be quite a task :)

Cheers,
MRb

jdMorgan




msg:4114592
 8:47 pm on Apr 12, 2010 (gmt 0)

Changing your mind *after* the site has been spidered, ranked, and linked-to is worse. Then you have to deal with redirecting all the previously-indexed URLs, and hope that most of their link-juice gets passed from old to new.

I have a passing familiarity with mod_rewrite [webmasterworld.com], so I'd like to point out that you'll be more comfortable with mod_rewrite if your 'mental picture' of its function is technically-correct: Mod_rewrite does not take "search-engine-unfriendly" URLs and "turn them into" anything. It is used (in this context) to associate a "friendly" URL with a script filepath, so that when a request for a friendly URL is received by the server, it invokes that script (and can pass parameters to it) in order to generate the correct content for that requested URL.

In this case, it is functioning as a requested-URL-to-server-filepath translator -- one of its three major functions.

The "changing of the URL" from "unfriendly" to "friendly" occurs when you edit the on-page link on your Web page or modify the script or database that is used generate that on-page link. URLs are defined on the Web by links on pages, while filepaths are defined inside servers. To illustrate this, put up a link to a non-existent page or even a non-existent domain. That URL now exists and will get spidered, even though it does not resolve to any content on any server... It's a perfectly-valid URL, but it just doesn't lead anywhere.

We frequently see confusion in this regard, and understanding the true process really does help.

Jim

Matthew1980




msg:4114598
 8:59 pm on Apr 12, 2010 (gmt 0)

Hi there jdMorgan,

We frequently see confusion in this regard, and understanding the true process really does help.


I must confess, I am guilty of the confusion, and I should have made it clearer in my post that you actually create the link for the server to interpret, and not the other way, that was my major misunderstanding of the concept.

But once you understand the logic to it, it is really a great help.

Sorry for being a little confusing there ;-p

Cheers,
MRb

Vespasian




msg:4114885
 7:46 am on Apr 13, 2010 (gmt 0)

Well, I didn't know that was possible. I'm mostly a content building person on the web, and the actual design, coding and what-not are always a learning process for me when I do something new. But, you have gotten me to thinking about it, and it sounds like it would be a good idea to keep the url as short and simple as possible. So, I'm going to experiment.

I assume this is done through the .htaccess file. What line should I put in the .htaccess file to test it out?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved