Forum Moderators: phranque

Message Too Old, No Replies

Redirect all requests for .html files to another domain

         

tigertom

7:37 pm on Oct 31, 2004 (gmt 0)

10+ Year Member



I want to redirect all requests, for all files ending in .html only, in a sub-directory, to the files of the same name, in subdirectory of the same name, on a different domain:

i.e.

[tootle.com...]

should redirect to

[DOODLE.com...]

and

[tootle.com...]

should redirect to

[DOODLE.com...]

and so on for all the files ending in .html only

-----

I've had a look 'round for the right code, but found nothing useful, and I'm not smart enough to work it out.

-----

topr8

8:55 pm on Oct 31, 2004 (gmt 0)

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



in your htaccess file write the following line

RedirectMatch 301 ^sub-directory/([a-zA-Z0-9\-]+).html$ [example.com...] [L]

added: this will catch any file with a name using the characters a-z,A-Z and hyphen(-)

tigertom

2:29 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



Thanks very much for doing that. I'd never have worked it out on my own.

tigertom

2:01 pm on Nov 3, 2004 (gmt 0)

10+ Year Member



Oops .. except it doesn't seem to work.

jdMorgan

9:22 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The [L] flag is for use with mod_rewrite only, and this code is for mod_alias.

Try this instead:


RedirectMatch 301 ^sub-directory/([^.]+).html$ http://example.com/sub-directory/$1.html

If "it doesn't work," please try to provide details on *how* it doesn't work (i.e. what does it do that it should not do, and/or what does it not do that it should do), and any information that appears in your server error log (if applicable).

Jim

tigertom

1:00 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



There's something wrong with the way the server is set up. I still get the original URL, even when I do a simple redirect. It's a cheapo hosting account, so that's probably the reason.

Thanks for your help. I'm going to save this page, as this sort of info is very useful.