[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help 301 Redirection rule

Posted on 2011-10-28
3
Medium Priority
?
297 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Fernanditos
3 Comments
 
LVL 4

Expert Comment

by:happysunny
ID: 37048355
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

0
 
LVL 3

Expert Comment

by:re-searcher
ID: 37050675
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

0
 
LVL 26

Accepted Solution

by:
arober11 earned 2000 total points
ID: 37051473
Hi

You've a typo on line 6 of you rewrite rule block, as "(.)" asks the rule to just the FIRST character, not a whole string (book+title), for the Rewrite. So for a start try changing line 6 to look something like:

1) Take the WHOLE URL path after the "/search/", and 302 rewrite it to the index call.
RewriteRule (.*) /search/index.php?query=$1 [L]

Open in new window


2) Take the WHOLE URL path after the "/search/", and 301 redirect it, adding a /pdf/ prefix.
 
RewriteRule (.*) /search/pdf/$1 [L,R=301]

Open in new window


3) Take the URL path after "/search/", up to the first "/", and 301 redirect it, adding a /pdf/ prefix.
RewriteRule ([^/]+)$ /search/pdf/$1 [L,R=301]

Open in new window


This article I wrote a wile back covers the basics of rewriting, may be of some use.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question