I must not have gotten a good nights sleep last night because what I thought should be a simple 301 redirect isn’t quite doing what I wanted.
Long story short a customer had their site hijacked by a lunatic webmaster so we scraped the old CFM site and created an HTML version until we can get him redesigned. All the file names are exactly the same except what was .cfm is now .html
I tried this:
RewriteRule ^/?([a-z/]+)\.cfm$ $1.html [R=301, L]
and it works but it isn’t redirecting them, so then I tried:
RedirectMatch 301 ^/(.*)\.cfm$ $1.html
Same thing, the file stays .cfm while rendering the page correctly
So what the heck am I doing wrong? Know it’s something stupid, maybe shoveling 2’ of snow melted my brain
So technically my code was right except for the space in the flags but it is acting as a rewrite, not a redirect … what I am looking for (and maybe I didn’t explain it correctly) is to actually send them to the .html page when they request the cfm page.
Oh and no worries on the DirectoryIndex … different server
Yup! However, you really should run the test I show in the tutorial to see whether mod_rewrite’s enabled on your new server, too. Aw, if it isn’t, you’d be throwing 500 errors all over the place!
The R=301 tells SEs that this change is permanent, i.e., update their db’s.
Did you use a / before the redirection? That’s when Apache starts to freak out (can’t tell whether it’s a physical or domain address - and that can be cleared by a restart of Apache).
If you don’t have mod_rewrite enabled, you’d only be getting 500’s.
:eek2: That list of file extensions is worthless! All you’d really want to do is to redirect if it’s not a file (!-f) but that’s NOT what you’re doing here. Simply:
RewriteEngine on
RewriteRule ^([^.]+)\\.cfm$ $1.html [R=301,L]
will change ANYTHING with a cfm file extension to the same request with an html extension. Isn’t that what you want to do?
Final check: Are you using Apache 2.x? If not, add a / after the leading ^; if you’re not sure, add /?. I’m sure we’ve been through this before but that’s the only thing that can go wrong with such simple code (when mod_rewrite is enabled).
If you continue to get the physical path to your file, RESTART Apache as it’s an Apache error which (from my limited experience) can only be cured by a restart.
The extensions were from a copy paste I did out of another file,
Anyways without the / after the first ^ I still get the whole path deal but when I add it I then get the correct url in the location bar but a file now found
Dangerous stuff that copy and paste! KNOW what you’re doing before you put it on your server!
Okay, with Apache 2.x, the leading / in the regex will NOT match so
RewriteEngine on
RewriteRule ^([^.]+)\\.cfm$ $1.html [R=301,L]
will merely strip the .cfm and replace it with .html.
That said, there could be other gremlins in your system. Another thread had Options MultiViews which took a filename from the middle of the path to redirect out of context. If the cfm was supported from within the cgi-bin, that place is outside the webspace (generally) and NOT subject to .htaccess (mod_rewrite).
First, as above, the RED / cannot be matched by Apache 2.x. On the other hand, you’re reporting it as giving the correct redirection which is … What does it do with ^/? rather than ^ or ^/?
Not sure about the gremlins at this point … the request for http://www.zenwindows.com/competitors.cfm is throwing a 404 even though the .htacess file should be pointing it correctly:
RewriteEngine on
RewriteRule ^/([^.]+)\.cfm$ $1.html [R=301,L]
BTW I tried it without the /after the first ^ and it gave me the whole path thing.
May I assume that you can link directly to the .html version of your pages? If not, that’s why you’re getting the 404s.
If you’re still not able to get to the .html version, then you need to post your ENTIRE .htaccess file (and probably PM me your httpd.conf and httpd-vhosts.conf as there may be some little thing in one of those which is upsetting the apple cart).
Did you try it with ^/? as I’ve suggested a couple of times? What happens with that?
Well while we are figuring this out I had to do it the old fashioned ‘ugly way’ with one RedirectMatch line for each file on the server … customer was freaking out