.htaccess tutorial

htaccess Elite


listed in google with the wrong urls 301 redirect

Ask your mod_rewrite and Redirection questions here, and get answers!

listed in google with the wrong urls 301 redirect

New postby steven » 04 Feb 2009 15:03

Hello, hope you can help

By being foolish I have caused several thousand pages to be listed in google with the wrong url

Example http://www.mysite.com/files/abc123/
Should be listed as
Example http://www.mysite.com/files/file-abc123/

Is there a way to 301 redirect them without affecting other files in that directory?

This is what I’ve been trying but no success so far

Code: Select all
# If file has required ending
RewriteCond %{REQUEST_URI} files/(.+)/\$
# and does not start with file-
RewriteCond %{REQUEST_FILENAME} !^files/file-
# Redirect to file of same name in files
RewriteRule ^(.*)$ http://www.mysite.com/files/file-$1 [R=301,L]
steven
 
Posts: 2
Joined: 04 Feb 2009 14:57

Re: listed in google with the wrong urls 301 redirect

New postby spaz » 04 Feb 2009 20:49

Have you tried either one of the following?

Redirect 301 files/abc123/ http://www.mysite.com/files/file-abc123/

Redirect 301 files/abc123/ files/file-abc123/
spaz
 
Posts: 4
Joined: 04 Feb 2009 20:41

Re: listed in google with the wrong urls 301 redirect

New postby steven » 04 Feb 2009 21:01

Hi spaz

Part of the problem is that I have otter files in the dir like /files/files-cba321 so I need to exclude files starting with file- from the rewrite or I would get /files/file-file-cba321. There are to many files to list individually.
steven
 
Posts: 2
Joined: 04 Feb 2009 14:57


Return to Redirect or Rewrite Questions