Closed mnabialek closed 9 years ago
Seems to me that this is more of a per-case issue that can be easily resolved in .htaccess by the developer.
Remember that just because you want index.php removed from the URL, doesn't mean that everyone else wants index.php removed from the URL.
That's true however I think such protection should work out of the box (with possibility to turn it off). In my own framework I always checked $_SERVER['REQUEST_URI']
and I was almost sure it is working the same here.
99% of developers haven't done anything with it (you can check sites developed in Laravel) and probably only less than 0.1% would need for some reason urls also with index.php working.
We can check sites made with Laravel how? There are no signs that Laravel is being used. Who knows what people are doing for legacy reasons.
imo, if you need this kind of thing to prevent an illusive "negative-SEO" attack, then you can add it in yourself.
@mnabialek Please give an example of the 99% of developers (and sites that you can check are developed with Laravel). The fact of the matter is that this is a point of flexibility. I myself have an internal app that routes above index.php.
I have to agree with @Garbee - if you need this kind of thing to prevent a "negative SEO" attack - then add it internally (Literally, just add a route filter) or worry about correct SEO practices.
Not tested, but along the lines of:
Route::filter('index_redir', function() {
if(strpos($url, "index.php") !== false){
return Redirect::to(str_replace("index.php/", "", $url), 301);
}
return false;
});
Route::get('user', array('before' => 'index_redir', 'uses' => 'UserController@showProfile'));
This has nothing to do with Laravel
You're just basically setting querystring variables, if you can guess the access point of any website (in this case index.php
) that "prettifies" URLs and how those querystring variables map to the framework's MVC logic or .htaccess redirections you can generate all the URLs you want.
Good find @bworwa :+1:
For me it does not change anything. Many sites do it wrong and it does not mean that you should not care.
However if I look at your examples:
http://stackoverflow.com/q/25008004/anything redirects to correct url
https://www.youtube.com/watch?v=PeHA6cnAoRs&anything have <link rel="canonical" href="http://www.youtube.com/watch?v=PeHA6cnAoRs">
in site source
I still think if possible framework should deal with wrong urls instead of allowing all urls to display the same content.
I use this code at top of public/index.php ...
/*
* --------------------------------------------------------------------
* REMOVE index.php from URI
* --------------------------------------------------------------------
*/
if (strpos($_SERVER['REQUEST_URI'],'index.php') !== FALSE )
{
$new_uri = preg_replace('#index\.php\/?#', '', $_SERVER['REQUEST_URI']);
header('Location: '.$new_uri, TRUE, 301);
die();
}
Works fine.
You are still assuming sites need the index.php removed. Some may not. If you want, submit a PR to laravel/laravel with the fix. That is the proper place for it, in application logic. So the developer can easily decide if they need that rerouting or not.
Either way, this is not an issue with the framework at all.
The similar problem will be if you use the following url:
http://laravel.com/index.php/docs/anything
This url is redirected to:http://laravel.com/index.php/docs
Abviously this was done at the app level https://github.com/laravel/website/blob/master/app/routes.php#L56-L62
stell error on 2023 laravel 10
Al
laravel.com
website was created in Laravel Framework it will be the url I want to show the issue (but in fact you can choose any other website created with Laravel and probably 99% of websites will have the same problem) - I've also tested it at localhost with Laravel 4.2.One of urls on this website is:
http://laravel.com/docs
However it seems that the following url will also work:
http://laravel.com/index.php/docs
Similar problems will be for main website url.
Default url is:
http://laravel.com
But also the following urls will also work:
http://laravel.com/index.php
and
http://laravel.com/index.php?anything
This situation can cause that competition could create urls for those unwanted urls with index.php and search engines will see duplicated urls for our whole website and finally we don't know which urls will be displayed in search engines (those without index.php or those with it).
The similar problem will be if you use the following url:
http://laravel.com/index.php/docs/anything
This url is redirected to:
http://laravel.com/index.php/docs
and of course it should be redirected to:
http://laravel.com/docs
On localhost (at
laravel.com
it doesn't work) it also seems that urlhttp://mydomain.com/index.phpdocs
would work - it will go to routedocs
even if there is no slash betweenindex.php
anddocs
in the urlAs solution I think Laravel should either by default check
$_SERVER['REQUEST_URI]
and if it starts withindex.php
it should make 301 redirection to correct url or in.htaccess
should be added rewrite rules to do 301 redirection