Forum Moderators: phranque
I know that you can use the following code in .htaccess to execute .html pages as PHP:
AddType application/x-httpd-php htm html
But, is there a code that can be used to accomplish running a single .html page as php instead of the above code that runs every page on the site as php?
I know that I could just change the .html to .php, but I really want to know if I can run a single .html page as php without changing the extension and without using the (AddType application/x-httpd-php htm html) code that will run all of my .html pages as php.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
<Files myfile.html>
AddHandler php5-script .html
</Files>
redirect 301 /index.html http://www.example.com/index.php
I also directed all of my old internal links to ../index.html to /
Now no matter if you type in example.com or click on an internal link / the address goes to example.com/index.php never simply site.com. Will this cause any search engine problems? If I take the redirect out then it will serve the php page without the index.php. Does this matter and why do my external and internal links only go to example.com/index.php and not simply example.com when I have 301 redirect active even if I am not typing in the old index.html extension?
[edited by: jdMorgan at 12:19 pm (utc) on Oct. 12, 2006]
[edit reason] Example.com [/edit]
DirectoryIndex index.php index.html welcome.html
DirectoryIndex is evaluated left to right, so if you have a file called /index.php a request for example.com/ will return the PHP page but not change the URL from example.com/ even if an index.html exists in /.
You'll need to beware of a couple of things: First, this file may already exist, and second, it may be hidden by your host. If that's the case, you'll need to unhide it first, download it, and then add the DirectoryIndex directive to it, again, with a plain-text editor, not a word processor. Instructions on how to unhide system files (identified by the leading dot) vary from FTP client to FTP client.
Jim
DirectoryIndex index.php index.html
Is this code correct and do I need to have more possibilities in the code, for example index.htm?
Also, does this code tell the server to check every page on my site for .php file first? If so, will this be a resource problem since only 2 (my homepage and news page) of my approx. 5,000 pages have the .php extension? The entire reason that I added the .php extension to my 2 dynamic pages was because I was told and I read that the following code, that I was using, would drain resources since it would check every page on my site for php first:
AddType application/x-httpd-php htm html
I thought it probably was not a good idea to use the AddType code since, again only 2 of my pages contain php code.
Did I do the right thing in changing my extension to .php on the 2 pages and adding the DirectoryIndex code and taking out the AddType code?
Will any of this make a difference to search engines?
All of these configuration directives are processed as part of the Apache API, and Apache itself is fairly "light" as far as program size, complexity, and CPU load go... You'll often see people using an old junker PC to host sites with Apache, because it's not a CPU-intensive job until you load up the site with scripts and database functions. So an old 400MHz PII machine can actually handle a fairly large site.
As far as adding ".htm" or other extensions -- only you know the answer. If you don't use that extension for directory index files, then you don't need to add it.
BTW, for best search engine results, always link to your directory index pages using the "/" URL, and not by using "/index.whatever". We've got several other SEO-related threads on domain and page URL canonicalization problems and resulting duplicate-content issues going right now, and I recommend that you read them to prevent future problems. Here's one: Duplicate Content - Get it right or perish [webmasterworld.com]
Jim
We have dozens if not hundreds of threads [google.com] here about www to non-www redirects and non-www to www redirects.
Jim