Forum Moderators: phranque

Message Too Old, No Replies

redirecting only one type of file from a folder

         

esllou

6:05 pm on Mar 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am looking to redirect all .shtml files from a folder /widgets/ to a fixed URL on the same domain, though have not been able to find this redirect code anywhere.

There are a lot of references concerning redirecting all the contents of a folder, but not only certain file types.

Is this possible with .htaccess?

jdMorgan

6:10 pm on Mar 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes it is possible with .htaccess, using either mod_rewrite or mod_alias directives.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

esllou

1:48 pm on Mar 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems as though RedirectMatch would also be suitable, wouldn't it?

Would this work:


RedirectMatch 301 /widgets/(.*).shtml http://www.example.com

[edited by: jdMorgan at 6:34 pm (utc) on Mar. 19, 2007]
[edit reason] example.com [/edit]

jdMorgan

6:33 pm on Mar 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RedirectMatch is part of mod_alias cited above, so yes, it should work.

RedirectMatch 301 ^/widgets/[^.]+\.shtml$ http://www.example.com/

Jim

[edited by: jdMorgan at 6:34 pm (utc) on Mar. 19, 2007]