Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Htaccess - Making Html To Parse Php


2 replies to this topic

#1 BuffaloHelp

    Sterling Archer

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 4,088 posts
  • Gender:Male
  • myCENT:50.18

Posted 23 December 2009 - 07:21 AM

I came across an interesting trick while I was trying to make multiple domains to be parked but each would have different index page. (See my previous post).

You don't have to rename file_as.html to file_as.php. You can eliminate the hassle of losing search engine link. There's another trick to redirect incoming ****.html to be redirected to ****.php, but for this demonstration purpose I'm just going to talk about including regular PHP expressions to regular HTML page.

I was faced with editing 100+ HTML files to have URL changed within each page. Although I could have easily done it with HTML editors, copy, paste, save and then upload, I wanted to know if I could do it in a way that would be better for the future. I mean what if I have to change this URL to another format, or include additional information to 100+ HTML files? Do I go through of editing them all over again? If they were a PHP file I would simply include 1 file which can be edited. Then the 100+ pages will reflect the change immediately by uploading a single changed file.

Using htaccess native command,

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Save this as .htaccess and upload it to the directory where your files will be affected.

Once uploaded, simple have your HTML file to include a code like
<body>
...
...
<?php
include ('filename.php');

//or

for ($i=0; $i<sizeof($array); $i++) {
   echo $array[$i];
}
?>
...
...
</body>
</html>

As you can see, although your file still possess file_as.html, you can make it to run PHP code. And all PHP codes will run normally--no exceptions or exclusions.

#2 Quatrux

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 605 posts
  • Gender:Male
  • Location:Lithuania, Vilnius
  • Interests:Programming
  • myCENT:49.19

Posted 23 December 2009 - 07:28 AM

I knew that for a long time, but be careful of using this, because when apache sends a simple html file, it sends the headers too by default if they are configured, but when you make it a php parsed file, the headers might change, so you need to control them with php, besides when you will want to run just simple html files, it will be slower rather than php.

I personally prefer to use mod rewrite and use url links like /category/section/mypage.html there you just control .html with PHP or something like that.. :P

#3 k_nitin_r

    Grand Imperial Poobah

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,114 posts
  • Gender:Male
  • Location:Dubai
  • myCENT:50.55

Posted 06 May 2010 - 05:31 AM

Hi!

@BuffaloHelp

The settings that you've provided for the HtAccess file hook up the PHP processor to files with the HTML interface. An alternative to get scripts from files that do not include the .php extension would be to read them through a PHP script and to evaluate the string. It achieves the same effect but would involve a greater overhead from having to do it through PHP instead of orchestrating the whole process through a C-coded application (both Apache and the PHP processor). The advantage of using HtAccess, however, is that it gives you the benefit of keeping the original URLs. You can also use the Mod_Rewrite module to get the .html in the URLs to map to the .php extension of the files without having to rename the files to .html. It's a better solution if you already have existing scripts uploaded to the server.

The file extensions do not have an effect on the search engine results because you have lots of content management systems that add in their file extensions to the URL and URL re-writing modules that take away the file extension entirely! On most blogs today, we see the article title as the name of the 'file' in the URL and there's definitely no association with the .html extension in that case. In fact, in traditional UNIX systems, file extensions are just vestigial appendages that were added on for the administrators to be able to figure out what they do - the file processing utilities are able to handle files with any kind of extensions. When creating the HtAccess file using Windows Explorer (of course, when trying to run Apache on a Microsoft Windows-based system), you can't really create a .htaccess file because it has no characters before the period - you cannot create a file that has only an extension and no 'primary' name in Windows. However, you can modify an existing .htaccess file normally so the only way to create a .htaccess file would be to programmatically create one, or create one on a UNIX based system and copy it across to the Windows based system either through FTP, SCP, or sending across an archive.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users