开发者

mod_rewrite help needed for 410 status code

I want to send 410 status code if there is any ? on the URL. Because the site is only works with SEO enabled URLs (Like www.domain.com/seo-enabled-urls).

With the StatckOverflow community support did this 301 redirection that works perfectly:

RewriteBase /
RewriteRule ^romance-package-two\.html$ http://www.domain.com/wedding-champagne [QSA,NC,R=301,L]

In the same way I want to add 410 message code that will tell Google (like search engines) permanently deleted so we wont have problem with SEO unknown or not found URLs.

If the URL开发者_如何学运维 looks like this

www.domain.com/seo-enabled-urls?param1=val1&param2=val2

I want to keep the same URL but just with that 410 code like this

RewriteCond %{query_string} ^(.*&)?$ [NC]
RewriteRule ^1$  same url code [QSA,NC,R=410,L]

Please help me.


You can't redirect with a HTTP 410 code -- 410 means that the requested page is permanently gone, and that there's no replacement:

410 Gone

The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is cacheable unless indicated otherwise.

-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11


The corresponding definition for HTTP 301 indicates that it's already exactly what you wanted:

301 Moved Permanently

The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.

-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2


The accepted answer is no longer correct at least as far back as Apache 2.0, where mod_rewrite supports a 410 GONE target:

'gone|G' (force URL to be gone) This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.

(see http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule)

That means that a rule such as you had above should simply be:

RewriteCond %{query_string} ^(.*&)?$ [NC]
RewriteRule ^1$ - [G]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜