Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch 301 .html except index

         

kfaer

10:23 am on May 12, 2012 (gmt 0)

10+ Year Member



hello,

i'm using

RedirectMatch 301 (.*)\.html$ http://example.com$1/

to redirect any .html page to / ending page but it also redirecting the example.com/ to example.com/index/

help to solve it please thank you

g1smd

10:31 am on May 12, 2012 (gmt 0)

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



Use a RewriteRule, not RedirectMatch. Add the [R=301,L] flags.

Set up a separate preceding rule that deals with index requests (redirect index.html requests to URL ending with slash).

URLs for pages should not end with a slash. URLs ending with a slash denote a folder.

Add a preceding RewriteCond checking THE_REQUEST to be sure that when the pointer is set to .html this is as a result of a direct request and not as a result of a previous internal rewrite.

kfaer

10:37 am on May 12, 2012 (gmt 0)

10+ Year Member



could you please how the should looks

incrediBILL

7:38 pm on May 12, 2012 (gmt 0)

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



This whole forum is full of such examples, many many of them.

lucy24

11:42 pm on May 12, 2012 (gmt 0)

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



RedirectMatch 301 (.*)\.html$ http://example.com$1/

to redirect any .html page to / ending page but it also redirecting the example.com/ to example.com/index/

Been there. Done that. It means mod_dir has already executed, so URLs ending in / have been rewritten (not redirected) to index.html. When you change to mod_rewrite you will be able to add Conditions. You need one looking at THE_REQUEST.