Forum Moderators: coopster

Message Too Old, No Replies

.htaccess to make a single .htm page process php?

         

kapow

5:47 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know I can add this to my .htaccess file to make all .htm pages in a folder parse php:

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

Can anyone tell me if there is a way to specify just one page to parse php, ie index.html?

Notes:
- My webserver has BSD, Apache, PHP
- I don't want to change the page name to index.php

jatar_k

6:25 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



no, I believe it is only by extension

zomega42

7:06 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



I haven't ever tried with php, but here's what I use on other app servers:

<Files index.html>
AddHandler myhandlername .html
</Files>

Try replacing my AddHandler with your AddType, see if it works.

Vishal

7:09 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



Try moving that single page into its own subdirectory and put .htaccess in that directory. Hopefully it will work.

Here is that I use in my .htaccess file

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

whoisgregg

10:21 pm on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is dead simple... Just change the filename from example.htm to example.php, then add this rewrite to your .htaccess:

RewriteRule ^example\.htm$ example.php [L] 

If you want to actually make the page look just like it's old html self, you'll also need to take a close look at the headers and send the correct ones with PHP.

coopster

12:09 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Personally I would go with the example mentioned by zomega42. Use the Apache <Files> container, -- ideal use.

kapow

1:53 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried Zomega42's solution and it works fine!

<Files index.html>
AddType application/x-httpd-php .htm .html
</Files>

I reolise the rewrite solution would work too but I'm a bit scared of changing header content as it might register to Google as a significant change on what is currently a high ranking page.

Thanks for the excellent input everyone!

whoisgregg

5:37 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, my comment made it seem like the headers warning only applied to the rewrite approach. In fact, any change from a HTML to a PHP generated page will change the headers sent, regardless of how you tell PHP to parse that HTML file.

Check the headers [webmasterworld.com] before the change and after the change to see the difference.

kapow

10:44 am on Apr 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Whoisgregg

Didn't see your reply (as I thought I had finised with this). Thanks for your info, I've been checking server headers for my .htm pages that do and do not parse php. I didn't know about this stuff (more learning to do...).

I see that with .htm pages that parse php I get this kind of thing in the header:
- X-Powered-By: PHP/...
- Set-Cookie: xyz...

So obviously if Google (and others) want to distinguish between static and non static pages they can. I have some very well ranking .htm pages that parse php - so perhaps I'm being paranoid? i.e perhaps it does not matter. (I bet there is a long debate about this question, that I have not been aware of).

Anyone who knows about headers + SEO care to comment?