Link to home
Start Free TrialLog in
Avatar of Fernanditos
Fernanditos

asked on

Help 301 Redirection rule

Hi,

The normal URL structure on my site is:

site.com/search/pdf/harry+potter

by accident I got lot of URLs indexed in Google this way:

site.com/search/harry+potter
site.com/search/book+title
etc...

The wrong URLs are leading to a page with error.

I need to write some 301 redirection rule on my .htaccess to redirect ALL links like

site.com/search/book+title

to

site.com/search/pdf/book+title

The attached code is the content of my .htaccess inside /search/ folder.

Please help, help!

Thank you in advance.
RewriteEngine On
RewriteBase /search/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.) /search/index.php?query=$1 [L]

Open in new window

Avatar of happysunny
happysunny
Flag of United States of America image

Have you tried redirecting it this way?  Do you know how many web pages are being indexed that way?

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

Open in new window

i want to say you answer but you made some mistakes.
SEO tip: instead or + using - it's better.

for redirecting site.com/search/some+thing to site.com/search/pdf/some+thing add following code to .htaccess
Options +FollowSymlinks
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]



# REDIRECT ALL /SEARCH/* TO /SEARCH/PDF/*
RewriteCond %{REQUEST_URI} /search/.*
RewriteRule search/(.*) search/pdf/$1 [R=301,L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial