# Adding "Link" Header

**URL:** <https://www.ruby-forum.com/t/adding-link-header/216649>\
**Category:** NGINX\
**Created:** [February 9, 2012, 11:44pm UTC](https://www.ruby-forum.com/t/adding-link-header/216649 "2012-02-09T23:44:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 9, 2012, 11:44pm UTC](https://www.ruby-forum.com/t/adding-link-header/216649/1 "2012-02-09T23:44:34Z")

</div>

To avoid SEO issues on my subdomains, I need to add a “Link” header to  
support Google’s canonical header. The format is as follows (from  
[Official Google Webmaster Central Blog: Supporting rel="canonical" HTTP Headers](http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html)):

Link: [http://www.example.com/white-paper.html](http://www.example.com/white-paper.html); rel=“canonical”

So, the add\_header command would need to reference $uri, but it also  
needs a semi-colon and double quotes. How can I add this header to my  
config?

Posted at Nginx Forum:

> **[Adding "Link" Header](https://forum.nginx.org/read.php?2,222185,222185#msg-222185)**
>
> To avoid SEO issues on my subdomains, I need to add a "Link" header to support Google's canonical header. The format is as follows (from http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html): Link:...

---

<div class="post-metadata">

**Author:** ![jwilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jwilson](https://www.ruby-forum.com/u/jwilson)\
**Post date:** [February 10, 2012, 12:28am UTC](https://www.ruby-forum.com/t/adding-link-header/216649/2 "2012-02-10T00:28:29Z")

</div>

On 9 Fev 2012 22h43 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> To avoid SEO issues on my subdomains, I need to add a “Link” header  
> to support Google’s canonical header. The format is as follows  
> (from

[http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html](http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html)):

> Link: [http://www.example.com/white-paper.html](http://www.example.com/white-paper.html); rel=“canonical”
> 
> So, the add\_header command would need to reference $uri, but it also  
> needs a semi-colon and double quotes. How can I add this header to  
> my config?

add\_header Link “\<$scheme://$http\_host$request\_uri\>; rel="canonical"”;

— appa

---

<div class="post-metadata">

**Author:** ![jwilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jwilson](https://www.ruby-forum.com/u/jwilson)\
**Post date:** [February 10, 2012, 12:32am UTC](https://www.ruby-forum.com/t/adding-link-header/216649/3 "2012-02-10T00:32:12Z")

</div>

10 февраля 2012, 02:44 от “jwilson” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> To avoid SEO issues on my subdomains, I need to add a “Link” header to  
> support Google’s canonical header. The format is as follows (from

[http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html](http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html)):

> Link: [http://www.example.com/white-paper.html](http://www.example.com/white-paper.html); rel=“canonical”
> 
> So, the add\_header command would need to reference $uri, but it also  
> needs a semi-colon and double quotes. How can I add this header to my  
> config?

location ~\* ^/(.\*)(.pdf)$ {  
add\_header Link “\<$scheme://$host:$server\_port/$1.html\>;  
rel="canonical"”;  
}

You can use $http\_host instead of $host:$server\_port, but if you get  
a request without the Host header, $http\_host will be empty.

Max
