How do I make my pages PHP without changing .htm to .php?
ktoz
Status: New User - Welcome
Joined: 09 Oct 2003
Posts: 4
Reply Quote
Is there any way I can run php without having to change my file extensions from .htm to .php? I don't want to lose my page rankings, plus I have lots of links coming into my site. Thanks for your help.
Back to top
.htaccess is the trick
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
You need to go into your .htaccess file, that should be on the website root directory, along with the index.htm file, download that, then add the following line to it:

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

Remember, keep each of these configuration items on separate lines, and always create a linebreak after the last item on your .htaccess file, hit 'enter', that is so the cursor is then on the line after the last text line, then save the file as .htaccess (don't forget the . it is part of the file name). Upload the .htaccess file in ASCII text mode, not binary or you might have some problems, just like you would do with any other text file.

This will make your files under the root, plus the index file, all now be processed as if they were php pages, now you're set, no changes, no loss of links or positioning on search engines.

If there was no .htaccess file in the root directory, just go ahead and make one, it's just a text file, save it as .htaccess, upload it in ASCII mode, and you'll be set.
Back to top
Thanks so much!!!
ktoz
Status: New User - Welcome
Joined: 09 Oct 2003
Posts: 4
Reply Quote
That worked perfectly, thanks so much, my pages are now running PHP exactly like I wanted, I didn't have to change a thing.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
.htaccess files are also where you can set your custom 404 page missing files, that means instead of getting that annoying white screen with blank white text you normally get on many websites when a page is moved or you typed the link in wrong, the user gets a nice little error page that lets them know, you can see an example here, this is for this forum, if you click on this bad address in our forums:

techpatterns.com/forums/forumsdf.php

you will get redirected to our forum error page.

Here is the .htaccess code for that:

ErrorDocument 404 /site/missing_forum.htm

In this case the error page simply redirects the user to the index page of the forum using a meta redirect.

Remember, add one line at a time, linebreak after each line, save, upload in ASCII mode, then you're set.

.htaccess files can be placed in any folder, but they cascade down, an .htaccess file only affects the files and folder below it, and will override commands of higher level .htaccess files, but try to avoid that since it can cause problems, except in simple cases like this.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours