301 Redirection Contradiction .htaccess

Discussion in 'HTML & Website Design' started by beyondthelimits, Jan 10, 2013.

  1. #1
    Hi,

    TASK#1
    I need to redirect http://www.domainname.com/index.html to http://www.domainname.com. For the purpose I am using following code and it is working fine.

    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ http://www.domainname.com/$1 [R=301,L]

    TASK#2
    I also need to redirect http://www.domainname.com/folder/index.html to http://www.domainname.com/folder.html. For the purpose I am using following code and it is also working fine.

    Redirect 301 /folder/index.html http://www.domainname.com/folder.html


    However, the problem is that when I used both above specified codes together as given below, the task#2 code doesnt work and it starts redirecting http://www.domainname.com/folder/index.html to http://www.domainname.com/folder/ instead of http://www.domainname.com/folder.html

    Options FollowSymLinks
    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ http://www.domainname.com/$1 [R=301,L]

    Redirect 301 /folder/index.html http://www.domainname.com/folder.html
     
    beyondthelimits, Jan 10, 2013 IP