Forum Moderators: coopster

Message Too Old, No Replies

(PHP) too many vars in URL still serves my pages

         

m8fyu

9:21 am on Feb 3, 2012 (gmt 0)

10+ Year Member



Hopefully I have posted this to the correct forum. I've been struggling for the last 2 days to figure out how I can get my web pages to display only when the correct vars are passed in the URL. Its driving me crazy.

For example. Say I have a page called www.mydomain.com/index.php?destination=antigua

This is how my internal links are structured.

However, if I go and type directly into the address bar something like www.mydomain.com/index.php?destination=antigua&language=martian the same page gets served.

I used webmaster tools yesterday and I saw some 'duplicate content' warning as it seems that both pages have been indexed by Google. I thinnk this is a huge problem for me and wonder if there is a way I can stop this from happening in the future? I need to only serve the page if the exact url is requested.

Thanks for any suggestions.

penders

9:47 am on Feb 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For Google to index these additional pages (with extra URL params) there are presumably links to these pages somewhere? Are these extra URL params completely erroneous? Perhaps they are simply old links?

Rather than validating the precise URL params on the page, and preventing access if additional params are included, I would include a rel="canonical" tag which includes the canonical URL for the page being accessed. This should avoid any duplicate content issues.

<link rel="canonical" href="http://www.mydomain.com/index.php?destination=antigua">

m8fyu

10:34 am on Feb 3, 2012 (gmt 0)

10+ Year Member



Thank you penders I will look into your suggestion immediately and post feedback.

g1smd

8:33 pm on Feb 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can restrict access to other URLs with a RewriteRule where it has a preceding set of RewriteConds that select or don't select specific patterns:

RewriteCond %{REQUEST_URI} !^a=1&b=2$
RewriteCond %{REQUEST_URI} &?a=1&b=2&?
RewriteRule .* - [F]


If the attached parameters are not "exactly" a=1 and b=2 AND the attached parameters "contain" both a=1 and b=2 then block the request.

Just in case the parameters are requested in a different order (which should also be invalid) you would also need:

RewriteCond %{REQUEST_URI} &?b=2&a=1&?
RewriteRule .* - [F]


Your real rules would also need to be more specific than .* for the RegEx pattern matching the path.