Welcome to WebmasterWorld Guest from 54.159.19.75

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess - is it me or the hosted server

     
8:49 pm on Nov 28, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 31, 2007
posts: 198
votes: 0


Here's the htaccess file:


redirect 301 /directory/old1.htm http://www.example.org/new1.htm
redirect 301 /directory/old2.htm http://www.example.org/new2.htm


But when it redirects, it adds the old file name like this:
http://www.example.org/new1.htmold1.htm
http://www.example.org/new2.htmold2.htm

which of course is not found

Am I doing something wrong here, or is there an issue with my hosted server?
Thanks!
9:09 pm on Nov 28, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Use RewriteRule and the [R=301,L] flag, not Redirect here.

It gives you more control.
9:26 pm on Nov 28, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 31, 2007
posts: 198
votes: 0


Thanks so much for the fast reply. The old files were in a directory no longer being used. The new ones are in the root directory and have different names.
Is this correct then?


RewriteEngine On
RewriteRule ^/directory/old1\.htm$ new1.htm [L,R=301]
RewriteRule ^/directory/old2\.htm$ new2.htm [L,R=301]
11:32 pm on Nov 28, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12702
votes: 244


No. In mod_rewrite unlike mod_alias you leave off the leading slash from the pattern but include it in the target. And-- this part is the same for both mods-- include the full protocol and domain name unless you're on a hosting plan that has already regularized the whole thing before it ever gets to your htaccess. (If so, it won't do any harm but isn't as essential.)

But your original Redirect version still should not have reappended the filename. mod_alias is only supposed to reappend the rest of the path, if any.
1:09 am on Nov 29, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 31, 2007
posts: 198
votes: 0


Thank you so much. I didn't think the original way I had it would cause it to append the filename either. But in any event, rewrite is working:

RewriteRule ^directory/old1\.htm$ http://www.example.org/new1.htm [L,R=301]

Thanks again