Add slash to the base url

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 are redirected to
http://localhost/anything/ but I am not able to redirect
http://localhost to http://localhost/

Am I missing something?

Thanks
Prateek Dayal

Hello!

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

[…]

requests. Urls such as http://localhost/anything are redirected to
http://localhost/anything/ but I am not able to redirect
http://localhost to http://localhost/

Am I missing something?

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

Maxim D.

Yes, “http://localhost” and “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

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

Thanks
Prateek

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

What point are you exactly referring to?

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

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

Best regards,
Piotr S. < [email protected] >

Hello!

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

Yes, “http://localhost” and “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

Again: “http://localhost” and “http://localhost/” are identical.
Always. There is no difference. It’s the same as
http://example.com:80/” and “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/”, as they are in fact different). But
it’s completely presentational, nothing more.

So assuming that I want http://localhost to 301 redirect to
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:

http://tools.ietf.org/html/rfc2616#section-5.1.2

: … 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.

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

It’s about presentation, nothing more.

Maxim D.

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 -
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 -
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=trailing+slash+seo

Thanks
Prateek

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

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

Best regards,
Piotr S. < [email protected] >

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

Regards
Prateek Dayal

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

I don’t see anything there that says that “www.google.com” and
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
I have seen this being mentioned on some other forums too. A quick
google search lists a lot of discussions -
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” translates to “/something”,
http://www.google.com/something/” translates to “/something/”,
but both:
http://www.google.com” and “http://www.google.com/” translate to “/”.

Best regards,
Piotr S. < [email protected] >

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs