Forum Moderators: phranque

Message Too Old, No Replies

Forwarding .html pages to .php for specific directories

         

supahoopsa

9:52 am on Sep 9, 2009 (gmt 0)

10+ Year Member



I have a website which many different directories, the site is quite old and as a result there are a mixture of pages with .php extension and some with .html

There are four directories as follows:-
mydomain.com/directory1
mydomain.com/directory1/directory2
mydomain.com/directory1/directory3
mydomain.com/directory1/directory4

Each of these directories contain approx 250 files with .html extension. I need to edit these pages and add some functionality which means that I need to change the extension to .php

Creating the new pages is not a problem. What Im getting stuck with is how to ensure that if anyone visits the site

eg mydomain.com/directory1/page17.html they automatically get forwarded to mydomain.com/directory1/page17.php

NB This needs to be set up to make both users and SE bots happy :-)

I am presuming I need to edit the .htaccess but the only way I know how is to add a separate line for every file (ie about 1000 lines).

Is there anyway to cut this down to a few lines.

Please remember that not ALL .html pages on the website need to be forwarded to .php only those in these four particular directories.

Any assistance would be gratefully accepted.

jdMorgan

6:10 pm on Sep 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If all .html files in all four directories are to be forwared --that is, redirected-- to .php files, then one single mod_rewrite rule should suffice. mod_rewrite's regular-expressions pattern matching will make short work of this.

However, just because you want to parse a file for PHP code doesn't mean you have to change the filename or the URL; You can always tell Apache to parse .html files for PHP code, either globally in example.com/.htaccess, or in separate .htaccess files in those directories only. See Apache mod_mime, AddHandler directive.

Jim

supahoopsa

2:22 pm on Sep 10, 2009 (gmt 0)

10+ Year Member



Hey thanks for the reply.

It was much easier than I thought. I was forgetting you could place a separate .htaccess file in sub directories.

DOH!