Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect is adding index.htm to new URL (and it breaks)

.htaccess, 301 redirect

         

blakemiller

1:05 pm on Mar 27, 2015 (gmt 0)

10+ Year Member



I am trying to redirect the contents of a folder to an entirely new domain. This is what I have installed (I've added a space after each http:// so the forum doesn't make it a real link)

RewriteEngine On
Redirect 301 /folder/index.htm http:// newdomain.com
Redirect 301 /folder/ http:// newdomain.com

When I visit just the http:// olddomain.com/folder/ (without any sub index page in the url) it redirects fine to the new site.

But Google has indexed the actual index.htm page so when the link is visited (say from google) the redirection looks like this:

http:// domain.comindex.htm which of course doesn't work. Any/all files that are in the /folder/ directory are being appended to the redirected URL. I want ANY file within /folder/ to be redirected to the single http:// newdomain.com

I've tried a bunch of variations and different codes but none work.

Thanks,

phranque

7:07 pm on Mar 27, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Any/all files that are in the /folder/ directory are being appended to the redirected URL. I want ANY file within /folder/ to be redirected to the single http:// newdomain.com

I would avoid this solution - Google will treat this as a "soft 404".

phranque

7:12 pm on Mar 27, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



also, note that RewriteEngine is a mod_rewrite directive and Redirect is a mod_alias directive so that first directive is doing nothing for you and in any case you want to avoid mixing directives from the 2 modules.

lucy24

9:32 pm on Mar 27, 2015 (gmt 0)

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



I suspect you've misunderstood how mod_alias (Redirect by that name) works. Unlike mod_rewrite, it works by reappending the rest of the path onto the target you specify. So a rule involving
/folder/ >> /newfolder
means
/folder/page >> /newfolderpage
/folder/index.htm >> /newfolderindex.htm
et cetera. In other words, your redirects are doing exactly what you've told them to do.

But Google has indexed the actual index.htm page

That's because you've allowed "index.htm" to be directly accessible. You have to add a redirect, so anyone who requests
/directory/index.htm
by name is redirected to
/directory/
alone.

By default, search engines will ask for all three of these forms:
/directory/index.html
/directory/
/directory
even if there are no links anywhere to the "wrong" forms. They don't automatically ask for "index.htm" but I have to assume that once they know a site uses .htm in URLs, they'll try it that way. So your index redirect is best expressed as
index\.htm
without closing anchor, so both .htm and .html will get redirected. Make it
index\.s?htm
if you've got those.

I won't bother to repeat the index-redirect code, since it's one of the Top Ten Apache Questions ever. There may even be a specimen in the forums library.

I've added a space after each http:// so the forum doesn't make it a real link

Well, we keep telling you to use example.com, but you just won't listen :(

phranque

10:43 pm on Mar 27, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



we keep telling you to use example.com


lucy24 means this - IMPORTANT: Please Use Example.com For Domain Names in Posts:
http://www.webmasterworld.com/apache/4452736.htm [webmasterworld.com]