开发者

Which is the correct/better rule in .htaccess file?

I want to remove a wiki section from my website which has been indexed by Google therefore I don't want to re开发者_JS百科move it and end up with loads of 404's when the pages are removed. I want to write a rule which will redirect all URL's requesting pages in the wiki to another single page. So basically I want to redirect any URL containing the folder name /wiki/ to another page. I'm a bit confused if this should be a RewriteRule:

RewriteRule ^wiki/* http://www.mydomain.com [R=301,L]

or a RedirectMatch:

RedirectMatch 301 /wiki/(.*) http://www.mydomain.com

Would appreciate some advice on which is correct/best and if this is the correct way to do it.

Thanks.


They both will do the same job. But this idea is not good from SEO point of view -- for SEO will be better to return 410 code (410 Gone -- page was here but no longer available).

In any case: RedirectMatch approach is recommended -- it uses slightly less CPU. On another hand, RewriteRule is more flexible.

For example: you have URL like example.com/wiki/somepage?say=hello. If you use RedirectMatch then new URL will be example.com/?say=hello -- as you can see query string was copied over. With RewriteRule you can easily and nicely drop it, so the new URL will be just example.com/.

Here are the rules (slightly optimized):

RewriteRule ^wiki/ http://%{HTTP_HOST}/? [R=301,L]

OR

RedirectMatch 301 ^/wiki/.*$ http://www.mydomain.com/?

The ? in both rules is for dropping existing query string. With RewriteRule it will not be there when redirect occurs (mod_rewrite is quite intelligent in this regard) while RedirectMatch is very straight forward and will keep it (which may look a bit odd if you are looking for really nice/proper URLs)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜