Forum Moderators: phranque

Message Too Old, No Replies

Permanent Redirect from dot whatever to dot htm

Linkers Don't Get It Right

         

Sally Stitts

8:55 pm on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I am not a programmer, so anything fancy I will screw up. Many times I have tried htaccess fixes, and have had to dump them immediately, because they froze my whole site. These fixes were from well-intentioned folks, who just don't quite get it right.

PROBLEM: I always use .htm as an extension. Google Webmaster Tools always reports a lot of links to my site, that get the extension wrong. For instance, .html, .htmanotherword, .htmthis, .htmthat, .htm-lengthy-bs, etc. Lots of them.

QUESTION: What would a simple permanent redirect look like, that redirects ALL malformed suffixes, on ALL of the site's pages, to a simple .htm? Can it be done?

And please, no "Rewrite" stuff. I have NEVER gotten one of those to do anything except blow-up everything. Like I say, I am not a programmer (although I do quite well on the web, in spite of myself).

Thank you for any proposed workable solution. I will only test this at night (keep any explosions out of prime time).

Of course, some linkers mangle what is to the left of the period, as well. But I can't do anything about that! Ha-ha.
.

jdMorgan

9:17 pm on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> And please, no "Rewrite" stuff.

OK, not that this is any simpler using mod_alias instead of mod_rewrite...

RedirectMatch 301 ^/(([^/]*/)*[^./]+\.htm).+$ http://www.example.com/$1

That should work for most cases where the requested URL is reasonably well-formed.

Jim

Sally Stitts

10:04 pm on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Wow. That looks really scary.
Greek is more understandable to me, and I don't know any greek.

I will try it tonight, and report back.
Thank you for the code.
.

g1smd

10:23 pm on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Beware that if you have ANY rules (now or any time in the future) on your site that use RewriteRule, you may get "unintended operation" by having both RedirectMatch and RewriteRule on the same site. In that case, the above code will need to be converted to use RewriteRule instead.

Sally Stitts

7:31 am on Jul 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Cool. Very, very cool.
Your code works like a charm (sheer magic, to me).

I typed in all manner of screwed-up suffixes, hit enter, and all I get is "sought-after-file.htm"

Thank you so much. No way could I ever do this, without years of training.

I am going to have to come back to this forum more often. This visit resulted in over 200 bad links becoming good (well, not really good . . . how about functional?). That should help a lot. And also on any future messed-up suffixes to come! Ha-ha. Thanks again.
.

jdMorgan

5:35 pm on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> No way could I ever do this, without years of training.

A few months studying the documentation and reading relevant threads here (not full-time!) followed by a few more months of careful code development, testing, and deployment with attention to details and results would do. :)

I'll admit to having had no 'training' whatsoever. I just 'read the books' quite thoroughly. Of course, that was many years ago...

Jim