Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

php - How to no index specific URLS?

I was searching around on how to no index specific URLs but I havent found any specific info on the following.

By adding the below

<?php if(is_single(X)): ?>
<meta name="robots" content="noindex,nofollow">
<?php endif; ?>

I would be able to no index the (X) where X could be the post ID, the post title of “Hello World” for example , or a post slug of “hello-world”.

Would if be possible to specify all URLs which start with the same post slug or title for example, as in the example below?

www.test.com/REF-123-mytest.html
www.test.com/REF-123-yourtest.html
www.test.com/REF-123-histest.html

Could I leave out all URLs which start by REF-123 for example?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By using robots.txt, you can disallow crawling.

By using meta-robots (or the HTTP header X-Robots-Tag), you can disallow indexing.

If you intend to forbid indexing, you shouldn’t disallow the URLs in robots.txt, otherwise bots will never know that you don’t want these URLs to be indexed.

In case you want to disallow crawling, you could use this robots.txt:

User-agent: *
Disallow: /REF-123

This would apply to all URLs whose paths start with REF-123 (case-sensitive!).

In case you want to disallow indexing, you could add to all these pages this meta element

<meta name="robots" content="noindex">

or send the corresponding HTTP header X-Robots-Tag:

X-Robots-Tag: noindex

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...