# Add slash to the base url

**URL:** <https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096>\
**Category:** NGINX\
**Created:** [March 31, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096 "2010-03-31T15:34:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/1 "2010-03-31T15:34:51Z")

</div>

Hi,

I am trying to add a trailing slash to every url and I have been able to  
[almost] achieve that with this rule

if ($request\_method ~\* get){  
rewrite ^(.\*[^/])$ $1/ permanent;  
}

The if condition is to prevent redirection of POST requests to GET  
requests. Urls such as [http://localhost/anything](http://localhost/anything) are redirected to  
[http://localhost/anything/](http://localhost/anything/) but I am not able to redirect  
[http://localhost](http://localhost) to [http://localhost/](http://localhost/)

Am I missing something?

Thanks  
Prateek Dayal

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 3:49pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/2 "2010-03-31T15:49:18Z")

</div>

Hello!

On Wed, Mar 31, 2010 at 03:34:51PM +0200, Prateek Dayal wrote:

[…]

> requests. Urls such as [http://localhost/anything](http://localhost/anything) are redirected to  
> [http://localhost/anything/](http://localhost/anything/) but I am not able to redirect  
> [http://localhost](http://localhost) to [http://localhost/](http://localhost/)
> 
> Am I missing something?

Yes, “[http://localhost](http://localhost)” and “[http://localhost/](http://localhost/)” are identical from  
HTTP point of view. It’s up to your browser to show it one or  
another way.

Maxim D.

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 3:52pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/3 "2010-03-31T15:52:22Z")

</div>

> Yes, “[http://localhost](http://localhost)” and “[http://localhost/](http://localhost/)” are identical from  
> HTTP point of view. It’s up to your browser to show it one or  
> another way.

Thanks for the reply. I understand what you are saying but from a search  
engine point of view, they are two different urls. In fact I am making  
this change after reading this in the google reportcard -  
[http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html](http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html)

So assuming that I want [http://localhost](http://localhost) to 301 redirect to  
[http://localhost/](http://localhost/), how do I go about doing it?

Thanks  
Prateek

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 5:14pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/4 "2010-03-31T17:14:12Z")

</div>

> Thanks for the reply. I understand what you are saying but from a search  
> engine point of view, they are two different urls. In fact I am making  
> this change after reading this in the google reportcard -  
> [http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html](http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html)

What point are you exactly referring to?

> So assuming that I want [http://localhost](http://localhost) to 301 redirect to  
> [http://localhost/](http://localhost/), how do I go about doing it?

You can’t do that. Both request are for “/”.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/5 "2010-03-31T18:25:38Z")

</div>

Hello!

On Wed, Mar 31, 2010 at 03:52:22PM +0200, Prateek Dayal wrote:

> > Yes, “[http://localhost](http://localhost)” and “[http://localhost/](http://localhost/)” are identical from  
> > HTTP point of view. It’s up to your browser to show it one or  
> > another way.
> 
> Thanks for the reply. I understand what you are saying but from a search  
> engine point of view, they are two different urls. In fact I am making  
> this change after reading this in the google reportcard -  
> [http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html](http://googlewebmastercentral.blogspot.com/2010/03/googles-seo-report-card.html)

Again: “[http://localhost](http://localhost)” and “[http://localhost/](http://localhost/)” are identical.  
Always. There is no difference. It’s the same as  
“[http://example.com:80/](http://example.com:80/)” and “[http://example.com/](http://example.com/)”. Port defaults  
to 80, path defaults to “/”.

I personally think that it’s better to write with trailing slash  
as it’s in line with directory links (“[http://example.com/dir](http://example.com/dir)” →   
“[http://example.com/dir/](http://example.com/dir/)”, as they are in fact different). But  
it’s completely presentational, nothing more.

> So assuming that I want [http://localhost](http://localhost) to 301 redirect to  
> [http://localhost/](http://localhost/), how do I go about doing it?

You can’t do anything. Server don’t see if there was “/” or not  
in the original URL, it always get request with “/”. RFC 2616  
explicitly requires “/” if there are no path:

> **[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](https://www.rfc-editor.org/info/rfc2616/)**
>
> HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068. \[STANDARDS-TRACK\]

: … Note that the absolute path  
: cannot be empty; if none is present in the original URI, it MUST be  
: given as “/” (the server root).

Maxim D.

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 6:33pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/6 "2010-03-31T18:33:15Z")

</div>

Hello!

On Wed, Mar 31, 2010 at 06:17:23PM +0200, Prateek Dayal wrote:

> > What point are you exactly referring to?
> 
> I am referring to Subject II: Urls and Redirects (page no 20). Also here

It’s all about directories, not about root. Feel the difference.

> is another example from Matt Cutt’s blog -  
> [http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260](http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260)

It’s about presentation, nothing more.

Maxim D.

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 6:17pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/7 "2010-03-31T18:17:23Z")

</div>

> What point are you exactly referring to?

I am referring to Subject II: Urls and Redirects (page no 20). Also here  
is another example from Matt Cutt’s blog -

> **[SEO advice: url canonicalization](https://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260)**
>
> (I got my power back!) Before I start collecting feedback on the Bigdaddy data center, I want to talk a little bit about canonicalization, www vs. non-www, redirects, duplicate urls, 302 “hij…

I have seen this being mentioned on some other forums too. A quick  
google search lists a lot of discussions -

> **[Google Search](http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=trailing+slash+seo)**

Thanks  
Prateek

> > So assuming that I want [http://localhost](http://localhost) to 301 redirect to  
> > [http://localhost/](http://localhost/), how do I go about doing it?
> 
> You can’t do that. Both request are for “/”.
> 
> Best regards,  
> Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [April 3, 2010, 5:21am UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/8 "2010-04-03T05:21:34Z")

</div>

Thanks for all the replies. I now see what I was missing earlier.  
Sometimes SEO advice on the internet can be confusing/wrong 🙂

Regards  
Prateek Dayal

---

<div class="post-metadata">

**Author:** ![prateekdayal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prateekdayal](https://www.ruby-forum.com/u/prateekdayal)\
**Post date:** [March 31, 2010, 6:39pm UTC](https://www.ruby-forum.com/t/add-slash-to-the-base-url/186096/9 "2010-03-31T18:39:06Z")

</div>

> I am referring to Subject II: Urls and Redirects (page no 20).

I don’t see anything there that says that “[www.google.com](http://www.google.com)” and  
“[www.google.com/](http://www.google.com/)” are different for search engines.

> Also here is another example from Matt Cutt’s blog -  
> [http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260](http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260)  
> I have seen this being mentioned on some other forums too. A quick  
> google search lists a lot of discussions -  
> [Google Search](http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=trailing+slash+seo)

This is just some random stuff you can find on the Internet.  
It doesn’t mean that there is any science, research or knowledge behind  
it.

And on top of that, you’re missing one important thing:  
“[http://www.google.com/something](http://www.google.com/something)” translates to “/something”,  
“[http://www.google.com/something/](http://www.google.com/something/)” translates to “/something/”,  
but both:  
“[http://www.google.com](http://www.google.com)” and “[http://www.google.com/](http://www.google.com/)” translate to “/”.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>
