Forum Moderators: phranque

Message Too Old, No Replies

Including PHP in HTML files

         

Psycho111

10:21 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



I heard that it's best to rewrite urls to have the .html extension instead of .php. How would you do this using the .htaccess file?

jdMorgan

5:02 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Psycho111,

File extensions don't matter. What does matter is that you don't want long dynamic URLs with complex query strings (A query string is not part of a URL, it is data to be passed to the resource *at* that URL).

So avoid things like:
example.com/index.php?action=shop&products=widgets&size=small&color=red&texture=fuzzy
example.com/index.php?action=shop&products=widgets&size=small&color=blue&texture=fuzzy

You'd do better to use:
example.com/shop/small-fuzzy-red-widgets
example.com/shop/small-fuzzy-blue-widgets

In the first case (query-based) you have one page (URL), index.php, with two query strings. In the second case, you have what appears to be two separate pages, so they will do better. No file extension is needed.

If you really want to change .php URLs to .html URLs:
1) Change your scripts and pages to output links as ".html" so that you see them as .html links in your browser.
2) Then use .htaccess to write them back to .php when they are requested from your server, so that your scripts will work properly.

Jim

BjarneDM

9:13 am on Feb 11, 2005 (gmt 0)

10+ Year Member



the simplest way is just to tell Apache/PHP that *.html files need to be parsed by PHP.

You just put this:

 <FilesMatch "\.html$" >
ForceType application/x-httpd-php
</FilesMatch>

in either httpd.conf or a .htaccess file

hakre

10:15 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BjarneDM is right, but the type ("application/x-httpd-php") can differ on various setups. you can find the correct type in httpd.conf or ask your administrator for it.