大网数据广告活动
网站运营与故障问答

How to set up a rel=canonical in PHP?

· 52CE 我爱测

I'm trying to add the rel=canonical tag to only one page. In order to add the tag, I need to add it to the part, in the mod_header.php file. This will add the same rel canonical tag to all the pages of my website. How can I add r…

问题原文

原帖链接 · André Craveiro · CC BY-SA 3.0

I'm trying to add the rel=canonical tag to only one page. In order to add the tag, I need to add it to the part, in the mod_header.php file. This will add the same rel canonical tag to all the pages of my website.

How can I add rel canonical to only one page. I don't want to do a 301 redirect, I want to add a rel=canonical tag.

Can this be done with some .htaccess code?

已采纳解答

原帖链接 · Evgeniy · CC BY-SA 3.0

Add to htaccess:

<Files "file.html">
Header add Link "<http://www.example.com>;rel=\"canonical\""
</Files>

For further info read: https://moz.com/blog/how-to-advanced-relcanonical-http-headers

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2015-09-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。