homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

PHP redirects
Redirect all .htm files to .php

 10:56 pm on Apr 30, 2009 (gmt 0)

I just built a new design and changed all of my files from .htm to .php

Is there one command I can use in the .htaccess file server side to redirect all of them?



 11:24 pm on Apr 30, 2009 (gmt 0)

Do not redirect them.


use a rewrite so that you continue to use the same old .html URLs as before but the rewrite now connects those URL requests to the new internal .php filenames,


rename the new PHP files so that they have the same filenames as before and use the same .html extension as before, and then use AddHandler to ensure those .html files are parsed for any PHP scripts within them.


In this way, users will see and use the same URLs that they always have. There is absolutely no need to change the URLs used by your site when you change from static HTML files to having HTML being generated by PHP scripts.


 5:23 am on May 1, 2009 (gmt 0)

Yeah, g1smd is right, his option 2 is probably the best.


 4:39 pm on May 1, 2009 (gmt 0)

I am sure you guys know what you're talking about, but unfortunatley I do not. I'm not even close to a php programmer. Where can I learn what this means, or is there code I can just use in an .htaccess file?

Also, something wierd happened to the .htaccess file that I had on the server. I had redirected each htm file individually to a php file, but when I opened that .htaccess file yesterday, it was blank. Why would that happen?


 1:53 pm on May 6, 2009 (gmt 0)

Not sure why that would happen.

To get php to be parsed use this to your .htaccess:

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

If that doesn't work and you are using php 5, this might help:

AddHandler application/x-httpd-php5 .htm .html

That will allow you to keep index.html as it is and put php code in it instead of renaming it to index.php

If you aren't sure, ask your hosts for help. Most will usually be more than willing to oblige.

Good luck!


 7:13 pm on May 6, 2009 (gmt 0)

*** I had redirected each htm file individually to a php file ***

No. Do NOT redirect .htm to .php because that creates new URLs out on the web.

Use the same URLs out on the web and implement a rewrite or a handler inside the server.

A rewrite is different to a redirect.

If your .htaccess went blank, something else wrote over it; possibly the control panel for your site.


 3:36 pm on May 7, 2009 (gmt 0)

Please explain why "creaing new URLs out on the web" is a bad thing. I don't understand this.

Where do I find more information about creating a rewrite or handler? I'm not familiar with these terms.


 1:54 am on May 11, 2009 (gmt 0)

Creating new URLs makes it so links that exist to them are broken, and also users who use those URLs will have to relearn them.

I tend to use any file extension I want and when I make links to the files, omit the extension. If you have Apache, setup Content Negotiation. See ]http://httpd.apache.org/docs/2.0/content-negotiation.html. Instead of using http://example.com/page.html or http://example.com/page.php visitors can just type http://example.com/page and Apache will just serve up the correct document (you can use .htm or .php!).

Also, in order to use PHP you do not have to use a .php extension. As said above, you can just setup PHP to work in .htm documents as well (I personally use PHP in .xhtml documents).


 8:16 am on May 11, 2009 (gmt 0)

Creating a new URL for a page creates Duplicate Content if the old one still directly serves content as well.

Moving to a new URL breaks all incoming links and search-engine listings pointing to the old URL for the page (with resultant loss of traffic), and leaves visitors seeing "Error 404" messages, if the old URLs are not being redirected to the new URLs.

You are better off keeping the old URLs on the web, and letting the server accept those requests and continue to directly serve the same content. There's several ways to do it, and all are simple and commonly-used solutions.

I would use .htm URLs on the web, and matching .htm files on the server with AddHandler to tell the server to look inside those files for PHP scripting instructions.

If you prefer the rewrite, where you match .htm URL requests with their respective .php files in the server, there have been at least four questions asked and answered about rewriting URLs to .php files in the Apache forum in the last few days. Start there for examples of both methods.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved