Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Having problems with a 301 redirect

Returns a 404

     
2:44 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am doing some shuffling on my site, and for various reasons I have moved a couple directories (and all their subpages) in my directory structure. To be kind to Goog and others, I have tried to run a 301 in Apache, thus:

RewriteRule ^old_path/Directory/(.*)$ new_path/_NEW_ Directory/$1 [L,R=301]

First, when I tested, I got 200's... and I realized I need to erase the old directory. SO I did. Now when I test, I get 404's....

As a variation, I tried:

Redirect 301 ^old_path/Directory/(.*)$ http:// www.mysite.com/ new_path/_NEW_ Directory/$1

Still 404ing...

Thanks for your input!

Dave
7:47 pm on Aug 16, 2010 (gmt 0)

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



RewriteRule ^old_path/Directory/(.*)$ http://www.example.com/new_path/_NEW_Directory/$1 [R=301,L]


The above code should work.

Clear your browser cache before testing.
8:17 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Where is this code located?

Jim
1:42 am on Aug 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jim:

in httpd.conf

Dave
1:52 am on Aug 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Weird.... now it works. Thanks. Don't think it was cache, as I was using a "service" to check the header codes.... Anyway, I am seeing a 301 now...
1:56 am on Aug 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, found the problem. so simple... so stupid...

Not: RewriteRule ^old_path/Directory/(.*)$

But: RewriteRule ^/old_path/Directory/(.*)$

The slash must be in there it looks like...
8:34 am on Aug 17, 2010 (gmt 0)

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



The slash must be in there it looks like...

if the rule is used in the server config file (httpd.conf) then the path will contain the leading slash indicating the root directory.
if the rule is used in the per-directory config files (.htaccess) then the leading directory path information will be stripped before pattern matching.

Note: Pattern matching in per-directory context [httpd.apache.org]
Never forget that Pattern is applied to a complete URL in per-server configuration files. However, in per-directory configuration files, the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting - without this, you would always have to match the parent directory which is not always possible.
2:47 am on Aug 19, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In addition, if the rule is enclosed in a <Directory> container in a server config file, then the path specified by that container will also be removed from the path 'seen' by the RewriteRule.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month