FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Save as .html or .php





ParsaAkbari
I was thinking some of my pages contain abseloutly no PHP but in the future i might add a PHP object, should i just save all my web files as PHP from the start even if there is no php code in thier to save the trouble??
Peterssidan
If you save as .html it's often easier to open it in your web browser offline. If you change from .html to .php later all the old links will be broken so maybe it's best to use .php from start. But if you begin to use PHP you will probably use things like ?mode=normal&bla=... in the url so the old links might get broken anyway.
It's hard to say what is best. It's up to you.
imagefree
if you are thinking to add php later, you should keep the file extension .php from the very beginning , otherwise you will face problems (like said above).
sonam
The second problem (if you think about it) is SEO. Ones when search engine grab your pages and give them some PR with changing extensions you will lose this PR.

Sonam
ParsaAkbari
sonam wrote:
The second problem (if you think about it) is SEO. Ones when search engine grab your pages and give them some PR with changing extensions you will lose this PR.

Sonam


Oh thanks for that piece of information very usefull indeed.

Is there not a "universal" extension that covers all.
Peterssidan
ParsaAkbari wrote:
Is there not a "universal" extension that covers all.
I think .php is "universal" enough.

It's possible to use mod rewrite to rewrite the urls so it looks like the extension is still the same even if they are not but that is an advanced feature and will probably cause you more problem than it solves. Simply use .php for all your files will probably be the best and easiest way.
Hogwarts
Why use an extension at all, I ask?

Honestly, they're just bloat to the URL. Browsers don't give a damn what the extension is as long as the MIME-type is correct. Sure, use them for images/media/whatever , but there really is no need to use it for your site's pages to have extensions.

Even Google doesn't use an extension for http://www.google.com/search?q=foobar Wink
imagefree
Hogwarts wrote:
Why use an extension at all, I ask?

Honestly, they're just bloat to the URL. Browsers don't give a damn what the extension is as long as the MIME-type is correct. Sure, use them for images/media/whatever , but there really is no need to use it for your site's pages to have extensions.

Even Google doesn't use an extension for http://www.google.com/search?q=foobar Wink


first of all, may be the google's non-extension file name is actually an internal redirect.
Secondly, it is important to have a .php (or other specified) extension for apache to to tell php compiler to parse the page.

Also if you dont have any extension, and you have just a static page, your page will be delivered to browser as text/plain instead of text/html.

One more thing is that the same problem of file extensions also occure with images/media etc, but if you are successfully using files without extensions (by applying different techniques), then u should be able to use images without extension as well. In my case, i have renamed all of my images to the numeric ID of image, that is saved in database.



There is another problem with extensions. Is is normally thought that if we include files with .inc, .txt, or other anyother extension than .php, then the code inside the extension will not be executed. I used .txt extension for a long time and saved very vital data inside those file, and included the data. Everything was working fine. (remember this type of inclusion of .txt and .inc files is insecure if you dont keep yout included files outside of site root). Rather i have noticed an opposite thing. Including .php file into php script is slower than including .txt or .inc file in some cases. (Its just my experience maybe not a reality).
Hogwarts
Oh joy! A post to tear apart every discernible meaning of.

imagefree wrote:
first of all, may be the google's non-extension file name is actually an internal redirect.
Secondly, it is important to have a .php (or other specified) extension for apache to to tell php compiler to parse the page.


No, really? And it's not redirecting it, it's rewriting it.

Thank you anyway, captain obvious.

Quote:
Also if you dont have any extension, and you have just a static page, your page will be delivered to browser as text/plain instead of text/html.


Unless of course you're rewriting it like any sane person.

Quote:
One more thing is that the same problem of file extensions also occure with images/media etc, but if you are successfully using files without extensions (by applying different techniques), then u should be able to use images without extension as well. In my case, i have renamed all of my images to the numeric ID of image, that is saved in database.


No, that's bad practice. There's no feasible need to rewrite them as the lack of a file type may hurt you in this case: i.e. when poorly coded bb-code parsers decide they require a file extension or when a person tries to save an image.

In addition, users will not be seeing this (meaning it'd have zero effect on them) and doing so will simply result in a poor signal-to-noise ratio, which is bad in any given circumstance.

Basically, doing so is the antithesis of doing it for actual pages and will likely hurt your site.
rockacola
Hogwarts wrote:
Why use an extension at all, I ask?


That's true.. you can simply have your page like http://www.foo.com/bar and have an index.html page in 'bar' folder..

When you ready to include php scripts, replace index.html with index.php and your url will remain http://www.foo.com/bar
Hogwarts
rockacola wrote:
That's true.. you can simply have your page like http://www.foo.com/bar and have an index.html page in 'bar' folder..


Actually, you can do this with clever rewriting or a routing system used by a framework (CodeIgniter/Symfony)
Daniel15
For the rewriting that Hogwarts mentioned, you can use something like this using mod_rewrite rules in a .htaccess file:
Code:

RewriteEngine on

# If it's not an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Nor is it a directory
RewriteCond %{REQUEST_FILENAME} !-d
# And the .php version exists
RewriteCond %{REQUEST_FILENAME}.php -f
# Rewrite it
RewriteRule ^(.*)$ $1.php [L]


Then, if you have a file called test.php in the directory the .htaccess is in (or any of the subdirectories), you can access it by just going to test (no extension).

Also, as sonam mentioned, SEO is another thing to consider. Generally, once your site is up, you shouldn't change any of the file names (because search engines will have indexed the pages). If you must change them, use a 301 Moved Permanently redirect on the old URL to go to the new one (you may do this using mod_rewrite too).

Smile
imagefree
Hogwarts wrote:
No, really? And it's not redirecting it, it's rewriting it.


URL Rewrite is infact internal redirect.

Quote:
Unless of course you're rewriting it like any sane person

this topic is about selection of extensions not "HOW-TO REWRITE". So, the originator of topic is much interested in simple contents rather than complex redirection/rewrite tricks. So, i explained the problem with simple extension-free pages.


Quote:
No, that's bad practice. There's no feasible need to rewrite them as the lack of a file type may hurt you in this case: i.e. when poorly coded bb-code parsers decide they require a file extension or when a person tries to save an image.


check it
Code:
[img]http://www.google.com/noimage[/img]

also trying to save an image requires proper HTTP headers, not extension. (There may be problems with IE (i dont know), but in reality image download depends upon Headers not extensions.
For example:
If you set mime type image/png and ur image is something like http://www.example.com/my-image/abcd and you force download it (sending headers Content-Disposition: attachment; it will show the file extension .png when you try to save it, and in opera it shows file name as image.png

To save an image that is already loaded in Browser (with or without an extension) just rightclick and download.
Hogwarts
imagefree wrote:
URL Rewrite is infact internal redirect.

It doesn't give new direction to it; the direction is already definite. If this distinguished between conditions before acting, that would be redirection. To each man his own. Let's not get off topic.

Quote:
check it
Code:
[img]http://www.google.com/noimage[/img]

also trying to save an image requires proper HTTP headers, not extension. (There may be problems with IE (i dont know), but in reality image download depends upon Headers not extensions.
For example:
If you set mime type image/png and ur image is something like http://www.example.com/my-image/abcd and you force download it (sending headers Content-Disposition: attachment; it will show the file extension .png when you try to save it, and in opera it shows file name as image.png

To save an image that is already loaded in Browser (with or without an extension) just rightclick and download.

And what of scripts that don't check mime-types, instead checking the file extension?

In addition, how would one be sure of what the contents of the recieved file will be before the headers are sent? http://google.com/logo is far less informal than http://google.com/logo.gif. In addition, things such as favicon.png require extensions.
imagefree
Hogwarts wrote:
And what of scripts that don't check mime-types, instead checking the file extension?

In addition, how would one be sure of what the contents of the recieved file will be before the headers are sent? http://google.com/logo is far less informal than http://google.com/logo.gif. In addition, things such as favicon.png(/ico) and feed.rss should have extensions.

this is the answer to your first question
Hogwarts wrote:
Why use an extension at all, I ask?

Very Happy
ParsaAkbari
Thanks guys... complicated lol Shocked
riccopt
if you are in a server that uses APACHE, you can use a .htaccess and set HTML files to be parsed as PHP... this way it won't matter if your site uses HTML or PHP... the only thing is that if your sites uses only HTML files it will load slower, since all the file requests will be processed by PHP before being delivered to the server (the difference on the speed is not really noticeable)...
I hope I have helped you a bit...

you can set it also on some control panels... where you have the FILE HANDLERS... simply set HTML to the PHP parser... that will also do the trick...
ParsaAkbari
Okay, all of this is extreamly confusing >.<.

There seems to be a simple solution, get apache is there no way to change cpanel for apache?
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.
Use mod-rewrite which i have no clue about.
swizzy
ParsaAkbari wrote:
Okay, all of this is extreamly confusing >.<.

There seems to be a simple solution, get apache is there no way to change cpanel for apache?
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.
Use mod-rewrite which i have no clue about.


You got it all messed up, simple facts.

If you use html, and then change extension to php, it might harm your search engine rankings.
If you use php, and the page changes (due to addition of parameters, etc.), you can always handle that afterwards, dont worry now.

So start saving html as php.
ParsaAkbari
swizzy wrote:
ParsaAkbari wrote:
Okay, all of this is extreamly confusing >.<.

There seems to be a simple solution, get apache is there no way to change cpanel for apache?
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.
Use mod-rewrite which i have no clue about.


You got it all messed up, simple facts.

If you use html, and then change extension to php, it might harm your search engine rankings.
If you use php, and the page changes (due to addition of parameters, etc.), you can always handle that afterwards, dont worry now.

So start saving html as php.


Yes but the problem is i have already saved all my pages as .html, so its too late now >.<.
sonam
Quote:
Yes but the problem is i have already saved all my pages as .html, so its too late now >.<.


No, it is not (just change extension or "save as..." the same pages and upload it if:
1. you didn't publish your site in search engine.
2. you didn't make link exchange with other sites and this will produce broken links on their sites.

Solutions,
1. If you haven't any ranking then you can publish your site in search engines again, btw it is much beter if you publish only domain without pages e.g. http://www.yoursite.com/ and all pages search engine will find thru your menu links or thru site map.
2. Contact your link exchange partner and ask for exchange extension in link. For link exchange is also good to make exchange only with your domain name.

Sonam
riccopt
ParsaAkbari wrote:
swizzy wrote:
ParsaAkbari wrote:
Okay, all of this is extreamly confusing >.<.

There seems to be a simple solution, get apache is there no way to change cpanel for apache?
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.
Use mod-rewrite which i have no clue about.


You got it all messed up, simple facts.

If you use html, and then change extension to php, it might harm your search engine rankings.
If you use php, and the page changes (due to addition of parameters, etc.), you can always handle that afterwards, dont worry now.

So start saving html as php.


Yes but the problem is i have already saved all my pages as .html, so its too late now >.<.


rename all the files to PHP...
it is quite simple if you have any BULK RENAME UTILITY installed on your PC
I use: Bulk Rename Utility -> http://www.bulkrenameutility.co.uk/Main_Intro.php

as for the links, all you have to do is use your HTML editor and replace all .html with .php on all the files of your site....

not much work... it would take about 10 minutes to get that done (unless your site has 2000 pages... than it would take about 30 minutes)
Fire Boar
ParsaAkbari wrote:
Okay, all of this is extreamly confusing >.<.

There seems to be a simple solution, get apache is there no way to change cpanel for apache?
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.
Use mod-rewrite which i have no clue about.


Frihost already uses Apache, as do pretty much all web servers. If you're not using Frihost and want to know if you're on Apache or not, it's really simple: you can simply make a php script:

Code:
<?php phpinfo(); ?>


And open it in a browser. "Server API" will be something like "Apache 2.0 Handler" if you're using Apache. cPanel is NOT the web server program: that's Apache. It's actually the web admin interface program, which incidentally runs off Apache.
Agent ME
ParsaAkbari wrote:
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.

PHP and javascript are completely different. PHP is a server side script to set up webpages and files to send to the client. Javascript is code that runs client side on the page in the web browser (or doesn't run at all if the client has it disabled or doesn't support it).

If you rename the pages to all end in .php instead of .html, it should be possible to use some .htaccess trickery to redirect anyone mistakenly accessing a page ending in .html to the same page ending in .php.
Stubru Freak
As riccopt already said, it's no problem to save all your files as .html. You can tell Apache to treat them as PHP files.
riccopt
Agent ME wrote:
ParsaAkbari wrote:
Change my PHP scripts into javascript. Because i dont think javascript needs special extension.

PHP and javascript are completely different. PHP is a server side script to set up webpages and files to send to the client. Javascript is code that runs client side on the page in the web browser (or doesn't run at all if the client has it disabled or doesn't support it).

If you rename the pages to all end in .php instead of .html, it should be possible to use some .htaccess trickery to redirect anyone mistakenly accessing a page ending in .html to the same page ending in .php.
of course it is possible... and it is quite easy... but I won't waste my time trying to explain to someona who already gave up on PHP to use JAVASCRIPT....
albuferque
riccopt wrote:
... but I won't waste my time trying to explain to someona who already gave up on PHP to use JAVASCRIPT....



Well, I'll do:

RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)\.html$ /$1.php

Regards
Stubru Freak
albuferque wrote:
riccopt wrote:
... but I won't waste my time trying to explain to someona who already gave up on PHP to use JAVASCRIPT....



Well, I'll do:

RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)\.html$ /$1.php

Regards


It's a lot easier to just tell Apache to parse .html files as php. Plus, that hides the php extension, which is a little more secure. You can do it by adding this to your .htaccess file:
Code:
AddHandler application/x-httpd-php .html
albuferque
Also you can try:

RedirectMatch 301 ^/(.*)\.html$ http://www.yourdomain.com/$1.php

This redirects the user's browser (and GoogleBot) to the.php-page when they request the.html page.
rockacola
Hogwarts wrote:
rockacola wrote:
That's true.. you can simply have your page like http://www.foo.com/bar and have an index.html page in 'bar' folder..


Actually, you can do this with clever rewriting or a routing system used by a framework (CodeIgniter/Symfony)


*sorry late reply*

But we are not talking about smart methods like rewrite or routing are we. Wink

Edit:.. actually for some reason.. you guys ARE talking about rewrite now... I think that's a bit advance for simple question like this... Confused
Stubru Freak
rockacola wrote:
Hogwarts wrote:
rockacola wrote:
That's true.. you can simply have your page like http://www.foo.com/bar and have an index.html page in 'bar' folder..


Actually, you can do this with clever rewriting or a routing system used by a framework (CodeIgniter/Symfony)


*sorry late reply*

But we are not talking about smart methods like rewrite or routing are we. Wink

Edit:.. actually for some reason.. you guys ARE talking about rewrite now... I think that's a bit advance for simple question like this... Confused


Advanced or not, all it requires is one file with some copy-pasted lines. That's a lot easier than having to make a separate directory for every file.
chatrack
ParsaAkbari wrote:
I was thinking some of my pages contain abseloutly no PHP but in the future i might add a PHP object, should i just save all my web files as PHP from the start even if there is no php code in thier to save the trouble??


I have a similar case when I first studied php. What I do is just rename all .html to .php and

changed all links. It was easy for me as i have few pages. I think it is not a large difficult task, to
rename all .htm or .html to .php, with the help of any text editor " Find- Replace" function

convert to php for better future!

am i right? Question
Jamestf347
Writing it as a .php would save time in the long run, and would only require a few lines more of coding, so i'd say add the lines and save it as a php, worst comes to worst you can just make it html.
Related topics
PHP Toturail
IP Address HTML CODE
HTML + PHP problem
Wonders of the include() in PHP.
how did you learn about html, php or other languages???
Save your codes from people
How to save HTML in Databases wise ly ?
A good place to learn html/php/javascript/etc....
Web form to save HTML table as spreadsheet
Need a Contact form from HTML/PHP
HTML AND PHP CODER NEEDED ASAP
The best php and html editor?
[help=html,php]Error en forma de contacto...
HTML/PHP Help (Contact Box)
editing webpages (.php or .html) without database/cms?
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.