homepage Welcome to WebmasterWorld Guest from 54.211.138.180
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Having problems with a 301 redirect
Returns a 404
carfac




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

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

 

g1smd




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

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.

jdMorgan




msg:4187916
 8:17 pm on Aug 16, 2010 (gmt 0)

Where is this code located?

Jim

carfac




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

Hi Jim:

in httpd.conf

Dave

carfac




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

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...

carfac




msg:4188045
 1:56 am on Aug 17, 2010 (gmt 0)

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...

phranque




msg:4188157
 8:34 am on Aug 17, 2010 (gmt 0)

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.

jdMorgan




msg:4188957
 2:47 am on Aug 19, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved