Welcome to WebmasterWorld Guest from 54.145.44.134

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess - is it me or the hosted server

     

vero

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

5+ Year Member



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!

g1smd

9:09 pm on Nov 28, 2011 (gmt 0)

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



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

It gives you more control.

vero

9:26 pm on Nov 28, 2011 (gmt 0)

5+ Year Member



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]

lucy24

11:32 pm on Nov 28, 2011 (gmt 0)

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



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.

vero

1:09 am on Nov 29, 2011 (gmt 0)

5+ Year Member



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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month