Remove ?p=n from querystring and 301 to clean URL

Hi,

Our urls used to be paginated - but we now have AJAX loader.

Our URL's indexed in Google are:
..................html?p=1
..................html?p=2
..................html?p=3

The rewrite rule needs to identify any URL's that contain "?p=n" immediately after ".html" and only on these do a 301 redirect to the same URL but without any querystring.

Help!
intangiblemediaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Ajax is for your visitors benefit, you still need to let Google etc index the paginated pages. Search engines wont execute ajax requests.
If you remove all links to the paginated pages then you will lose all those pages from Google etc. ergo search traffic
0
intangiblemediaAuthor Commented:
Thank you, but we are no longer using pagination - and these querystrings no longer affect the product listing, so it is actually causing duplicate content in Google's eyes.
0
GaryCommented:
And how does Google get the rest of the content?
Assume you are registered with Google Webmaster Tools, you can set what params do under the Crawl index.
In your htaccess, this will remove the whole querystring!

RewriteEngine On
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^(.*)$ /$1? [R=301,L]

Open in new window

0
DropZoneCommented:
Hi,

Try the following.  It detects the "p=..." as the first argument in the query string (as you requested), which may be followed by any other argument which you may want to keep.

So something like "http://www.example.com/index.html?p=1&a=foo&b=bar" would turn into "http://www.example.com/index.html?a=foo&b=bar".

RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=\d+(\&(.+))?$
RewriteRule ^(.*)$ /$1\?%2 [R=301,L]

Open in new window


If you dont know if the "p=..." argument is the first one, then you need to use a more complex rule, like this:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^((?!:p=)[^&]*&)*p=\d+(\&(.+))?$
RewriteRule ^(.*)$ /$1\?%1%3 [R=301,L]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.