Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforcing Trailing slash or not routes #1807

Closed
rclai opened this issue Jan 6, 2014 · 26 comments
Closed

Enforcing Trailing slash or not routes #1807

rclai opened this issue Jan 6, 2014 · 26 comments

Comments

@rclai
Copy link

rclai commented Jan 6, 2014

I think it is paramount that routes enforce a trailing slash or not, in the sense that if I configure my routes to have a trailing slash, and I access the URL without the slash, that it should 301 to the one with a trailing slash. Same thing if I configure it not to have a trailing slash, that it would 301 a request with a trailing slash to the one without it.

This is important for SEO.

@samdark
Copy link
Member

samdark commented Jan 6, 2014

Agree that it's better behavior but don't agree that it has any impact on SEO.

@rclai
Copy link
Author

rclai commented Jan 6, 2014

Well, it would affect SEO if a route returned 200 on both trailing slash and without and it serves the same content. You'll get duplicate content issues.

http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html

@samdark
Copy link
Member

samdark commented Jan 6, 2014

@rclai yes, but it's not the case with Yii2.

@rclai
Copy link
Author

rclai commented Jan 7, 2014

okay cool

@djagya
Copy link
Contributor

djagya commented Jan 9, 2014

May i make these?

@samdark
Copy link
Member

samdark commented Jan 9, 2014

Yes, feel free to make a pull request.

@djagya
Copy link
Contributor

djagya commented Jan 9, 2014

These "slashes or not" should be written in the routes? For example:

'blog/index/' => 'blog/index',
// /index.php/blog/index/ (with slash)
'site/about' => 'site/about',
// /index.php/site/about (without slash)

Or how they should be configured? One general parameter for the UrlManager component?

@samdark
Copy link
Member

samdark commented Jan 9, 2014

Hmm... good question @yiisoft/core-developers what do you think?

@qiangxue
Copy link
Member

qiangxue commented Jan 9, 2014

I think this issue is about automatically performing 301 redirection.

We use suffix (at UrlManager level and/or UrlRule level) to specify whether a URL should end with a slash.

@djagya
Copy link
Contributor

djagya commented Jan 9, 2014

@qiangxue uh, ok, sorry. Yes, it's definitely enough. Then there is no more questions

@samdark
Copy link
Member

samdark commented Jan 9, 2014

So should we redirect from unsuffixed URL to suffixed URL? What about redirecting from / to URL w/o suffix?

@qiangxue
Copy link
Member

qiangxue commented Jan 9, 2014

Either direction is possible. There should be an option at manager and rule levels that toggle this behavior.

@dilip-vishwa
Copy link
Contributor

I agree with the above that it affects the SEO.

We should make sure that

  • All links should have /. This ensures that the indexing robot will always get to url with 200 status.
  • If the user has not used the / in url, then we should redirect it. So, now it only affects User and not the SEO.

Above solution is the most preferred in the SEO based url.
💯

@samdark
Copy link
Member

samdark commented Jan 11, 2014

@dilip-vishwa it does not affect SEO for the reasons I've stated above.

@rclai
Copy link
Author

rclai commented Jan 12, 2014

You stated reasons?

But anyway, it doesn't matter, like @qiangxue said, just as long as we can get an option manager and rule levels to toggle the behavior.

@samdark
Copy link
Member

samdark commented Jan 12, 2014

@rclai confused with another pull-request where I did. Here's the explaination from Google: http://googlewebmastercentral.blogspot.ru/2010/04/to-slash-or-not-to-slash.html

No duplicate content — no problem. There's no difference between post/25 and post/25/ if only one variant is possible.

Anyway, current plan is good.

@dilip-vishwa
Copy link
Contributor

But if user don't use trailing slash, then they will get 404 error which is not good for the business.

@creocoder
Copy link
Contributor

@dilip-vishwa Need trailing slash — use suffix. Do not need trailing slash — do not use suffix. Need redirection? This not Yii issue, this is for Web server. But:

We should make sure that:

  • All links should have /. This ensures that the indexing robot will always get to url with 200 status.
  • If the user has not used the / in url, then we should redirect it. So, now it only affects User and not the SEO.

Absolutelly meaningless. Yii should not act like this. This is about configuration.

@dilip-vishwa
Copy link
Contributor

@creocoder OK

@djagya
Copy link
Contributor

djagya commented Jan 14, 2014

Ok, soo what should i do? Will be there redirection or it is for web server?

@samdark
Copy link
Member

samdark commented Jan 14, 2014

I am for configurable redirect on framework side.

@creocoder
Copy link
Contributor

@samdark I'm against. This is web server task. For apache this can be achived through mod_rewrite, for other web servers there is another approaches. Such task should be solved at web server level. Redirect rules for SEO purposes is not framework issue.

@samdark
Copy link
Member

samdark commented Jan 14, 2014

Thought about it a bit more and @creocoder may be right about it.

@Bhoft
Copy link
Contributor

Bhoft commented Mar 18, 2015

I can understand the issue with the trailing slash when using slugs or actions.
There the usage of the suffix property is usefull if you want some ".html" added to the urls.
In my issue posted #7670 i had the problem with a custom url rule where i have to add several url rules so that these urls
are working

/projectname => projectcontroller/index
/projectname/ => projectcontroller/index
/projectname/action => projectcontroller/action

/projectname/projectspecifc_controller => projectspecifc_controller/index
/projectname/projectspecifc_controller/ => projectspecifc_controller/index
/projectname/projectspecifc_controller/action => projectspecifc_controller/action

So I have to add only for the trailing slash an additional url rule, where the suffix is set.
But can't it be changed that we could also set an "optional" suffix?

suffix = ".html" 
can then be used for rules with actions and 
optional_suffix = "/" 
can be used for rules only to controllers.

That way all possibilities can be set and on parseRequest there is then also a check if pathInfo has the optional_suffix added.
Or there is some other possibility to set some parts of the url pattern to be optional checked.

This issue is I guess somehow strange because without custom rules you will get the handling that controllername/ would call the index action. But with custom rules you will have to add an additional rule to have this to be able to set something like this (?:[/])?
Which i also mentioned here #7670 (comment)

samdark has written in my issue:
Yes, there's difference and it's intentional.

But then why it is possible to call site/ and get the index action instead of a 404 with no custom url rules.
The Url handling should be the same regardless of additional rules are added or not.
Also in yii1 this how the trailing / was handled there with the same url rules.

@jahangirahmad
Copy link

So now we need redirect one of them to other? right?
how can I redirect 301 in yii2(php code) without slash to url that has slash?
ex:

domain.com/item/10/item-slug 

TO

domain.com/item/10/item-slug/ 

@cebe
Copy link
Member

cebe commented Nov 20, 2015

see #7670 it has some solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants