Link to home
Start Free TrialLog in
Avatar of redpoppy
redpoppy

asked on

Redirecting .htm to .php

Hi Experts,

I expect this is an easy one for someone who knows .htaccess, but I can't figure it out:

I want to redirect all calls to .htm files in a particular directory on my web site to the same directory/filename but with a .php extension.

I tried: redirectmatch 301 /Brochures/*.htm http://www.mysite.com/Brochures/*.php but this doesn't seem to work.
Avatar of ClickCentric
ClickCentric

Ok, first, if you only want to do this in the Brochures directory, I'd suggest putting the .htaccess file there.  It could save aggravation later if something you do starts triggering it for some reason.

Then, all you'd need to put in the .htaccess file is:

RewriteEngine On
RewriteRule (.*)\.html$ $1.php
SOLUTION
Avatar of ClickCentric
ClickCentric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of redpoppy

ASKER

Hi ClickCentric, thanks for quick reply - I tried both of your suggestions, but neither worked. Might it be because I already have a .htaccess file in the root directory, although there aren't any enties there concerning this particular directory? Is it possible to put something into the existing .htaccess file if this is the problem?
Hmm...odd that neither would work.  The first almost definitely should.  For the second, though, I think RewriteEngine On also has to be at the top of that file.  If neither worked, you have a bigger issue at hand.  Either there's something directly competing with it in your top-level .htaccess file (can you post this?) or your apache doesn't have mod_rewrite enabled in which case things are a bit more complex.  
Although, after double-checking, RedirectMatch is part of mod_alias, not mod_rewrite.  Though it could still be that the module isn't available.  You may have to ask your hosting provider.
Hi again, thanks for replying again. Here is the .htaccess in the root directory, given to me by my ISP:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?natmor.co.uk/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]

redirect 301 /newsg http://www.natmor.co.uk
redirect 301 /opt-real-mor.htm http://www.natmor.co.uk/index.htm
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, oops...yeah, I'm so used to it being .html that I completely missed that.  If you were using what I had verbatim, that well could be the problem.
Hi jason1178 - yep, that was it! Thanks a lot for your help and yours, ClickCentric - you both helped me out, so I've done a points split, hope you're both OK with that. Thanks again.
Yeah, I thought it unusual that it wasn't working, but despite looking at it a dozen times, I never noticed the .htm thing.  I guess my brain was just filling in the 'l'.  This is why it's often good to have someone new in the mix if a problem lingers after a while.  Sometimes it's something so simple that it slips through the cracks. :P