Forum Moderators: Robert Charlton & goodroi
www.example.com
www.example.com?x=1
www.example.com?x=2
www.example.com?x=3
You get the picture? Is there a way to return a 410 for the extra results without affecting the original page?
Any comments appreciated. thanks
[edited by: ciml at 1:47 pm (utc) on June 30, 2005]
[edit reason] Examplified [/edit]
As soon as i noticed it did what bird suggested you to do (301s) but about 2-3 past and these 503 copies are still in the index. Though they are supplemental but i would still rather not have them.
it simply checks for the presense of a variable and redirects if the variable is found.
you could do it through .htaccess too but i am not good at that.
if you can use php just copy eduardomaio's code to the top of your main page.
<?
if (isset($QUERY_STRING) and $QUERY_STRING)) {
if (410) { // you can either send 410 Gone
header("HTTP/1.1 410 Gone");
}
else { // or redirect permanently with 301
header("HTTP/1.1 301 Moved Permanently");
header("Location: [domain.com");...]
}
exit;
}
?>
In contrary to the previous PHP example, this is independent of the name of variables after? mark.
Using mod_rewrite is a bit more tricky, because using simple RewriteRule may have problems with seeing what's after quotation mark. You'd probably have to use RewriteCond on QUERY_STRING variable.
[webmasterworld.com...]
(you don't need php and you don't have to change any file names)
This will tell Google and others not to index that page, but will still allow you to set cookies on the visiters browser.
RewriteEngine on
RewriteCond %{QUERY_STRING}!^$
RewriteCond %{REQUEST_URI}!/boards/
RewriteRule .* http://www.example.com/ [R=301,L]
(there is a space before the quotation mark). My htaccess works fine otherwise with about 10 functioning 410 redirects in it. Any thoughts on what my next step could be?
I'd really like to avoid going to PHP.
-------------------------
1) Turn on the rewrite engine
2) If there is a query string, AND
3) The directory "/boards/" is not the current one, THEN
4) Redirect all requests to the home page with a 301, AND
5) Do no more for that request ( the [L] flag)
------------------------- So, it ought to work.
Have you used the [L] flag earlier in your ".htaccess" file? If yes, try removing it from the previous rule(s).
Have you turned on the rewrite engine two or more times in your ".htaccess" file? If yes, try doing it only once.
Is "/boards/" a physical directory, or is it a virtual one that only exists as a rewrite? (ie. it's really a parameter in a dynamic URL). If so, the real URL must be used in stead.
Apart from the above three, I really can't see what could be wrong here. So, try posting in the Apache forum if these tips don't help.
RewriteCond %{QUERY_STRING} 123
RewriteRule .* http://www.example.com/ [R=301,L]
RewriteCond %{QUERY_STRING} 1234
RewriteRule .* http://www.example.com/ [R=301,L]
That's the easy part... Getting G to respider quickly them is the hard part :)
I'm sorry if I forgot to double check the rewrite rule against this. If you pass on everything with the "$1" parameter, then of course the query string will be passed on as well.
So, this will make a loop:
RewriteRule (.*) http://www.example.com/$1 [R=301,L] ... while this will not:
RewriteRule .* http://www.example.com/ [R=301,L] I personally redirect my unwanted query strings to a non-existing page (that way serving a 404), so I haven't experienced this problem myself.
Right this moment I have no idea about how to solve it, but I'll take a look at the threads to leave a remark at least (if possible).
All scripts are perl and reside inside the cgi-bin folder structure.
This ruleset issues a forbiden error. This is a custom error page on our servers.
You could issue a 410 gone by changing the [F] to a [G].
If you have other scripting systems you'll have to modify this rule set to cover them as well.
If your site is static html this would work as well.
RewriteCond %{QUERY_STRING}!^$
RewriteCond %{REQUEST_URI}!^/cgi-bin
RewriteRule ^(.*)$ - [F]
Claus I'm chasing a better way to handle this mess but I'm running into a wall currently.
Testing is a royal pain as the .htaccess file is getting complicated.
The problem with "gone" is that this one assumes that there was content, which there is no longer access to. This is clearly not the case either.
You would want to issue a 404 in stead:
---------------------------------------------
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule .* /any-filename-that-does-not-exist.htm
---------------------------------------------
By making an internal redirect (no "R" flag) to a filename that does not exist, your normal 404-rules will take over and display whatever page you have set up to handle a 404 error (or the default, if none).
Of course, the server status code "404" will be issued as well.
However, using the URL-console you can remove your pages if they return a 404, or you can redirect them using the code above, to a real, existing, html file with the robots meta tag "noindex".
Well, that's odd, but then it is unexpected that somebody would redirect to something that's not there, so in a sense the server's right.
Just kidding of course. The 500 error is sort of a fallback status code when something went wrong and no other code seems to make sense, so it could be anything. I'd look through the error logs to see if I could get any closer to the core of the problem.
In the meantime I'd probably use the [G] or [F] flag in stead.