Laravel slash after url redirects to root folder

后端 未结 5 611
梦谈多话
梦谈多话 2020-12-18 08:02

I\'m new to Laravel and it seems a great framework but i have a question when it comes to routing. I want to route all get requests to one controller action named PageContro

5条回答
  •  余生分开走
    2020-12-18 08:36

    If you specify those routes in the opposite order it should work. Do your most specific routes first, and the more generic ones later. Think about it as a "catch this, this, and this, and then fall back to this generic one when none of the above match".


    Your new problem lies in the (bad, IMO) redirect rule that Laravel 4.1 ships with. The rules very much assume that your Laravel public directory sits on the document root of the server. Here's the rule:

    RewriteRule ^(.*)/$ /$1 [L,R=301
    

    As you can see, that's saying "if the current URL ends in a slash, just redirect it to /{url}", thus getting rid of the slash. This is all well and good, just as long as your installation sits on your server's document root.

    You can fix this by specifying a RewriteBase (in your case RewriteBase /laravel/public) above that rule in your public/.htaccess file, but of course, this will now change from environment to environment. This is why i consider the changing of Laravel 4.0's RedirectIftrailingSlash functionality to be a .htaccess rule to be a bad idea.

    Alternatively, you can remove that RewriteRule entirely and try not to worry about the fact that your app will now respond on both URLs /laravel/public/admin and /laravel/public/admin/.

提交回复
热议问题