禁用特定文件夹/路由的 Laravel 路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18075290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable Laravel Routing for a specific folder/route
提问by Mitchell M
I'm wondering how to disable the routing on laravel for a specific directory?
我想知道如何禁用特定目录的 laravel 路由?
I am hoping to run my main website off of laravel (I'm rewriting it into the framework), but I'd like to retain my current forum software! The problem is, when laravel sees the "localhost/forums" it looks for a forums controller or route. I'd like it to simply go to the literal /forums directory..?
我希望从 laravel 运行我的主网站(我正在将它重写到框架中),但我想保留我当前的论坛软件!问题是,当 laravel 看到“localhost/forums”时,它会寻找论坛控制器或路由。我希望它只是转到文字 /forums 目录..?
回答by George D.
I had to add this line in public/.htaccess
我不得不在 public/.htaccess 中添加这一行
RewriteCond %{REQUEST_URI} !^/foldername
before this line (that redirects trailing slashes)
在此行之前(重定向尾部斜杠)
RewriteRule ^(.*)/$ / [L,R=301]
回答by KyleT
With Laravel 4 none of these solutions were working for me. I eventually solved it by placing
使用 Laravel 4,这些解决方案都不适合我。我最终通过放置解决了它
RewriteRule ^(directory-name) - [L]
before
前
RewriteRule ^(.*)/$ / [L,R=301]
in public/.htaccess
在公共/.htaccess
回答by Mike Rockétt
You need to make an exclusion in your .htaccess
file. Just above the rule that sends everything to index.php
, add this:
您需要在.htaccess
文件中排除。在将所有内容发送到 的规则上方index.php
,添加以下内容:
RewriteCond %{REQUEST_URI} !^/forums
Anything that begins with /forums
will not be sent to Laravel.
任何以 开头的东西/forums
都不会被发送到 Laravel。
(Of course, this is assuming you are using Apache.)
(当然,这是假设您使用的是 Apache。)
回答by Andreyco
According to your routes.php
file it is supposed to work.
根据您的routes.php
文件,它应该可以工作。
- You are not catching
forum
URL at all - If 'forum' directory/file exists, URL is not rewritten to Laravel's
index.php
- 你根本没有捕捉到
forum
URL - 如果 'forum' 目录/文件存在,则 URL 不会重写到 Laravel 的
index.php
routes.php
(I used this one in the test case)
routes.php
(我在测试用例中使用了这个)
Route::get('{slug}', function($slug){
return $slug;
});
File structure
文件结构
|- app
|- public
|--- index.php // Laravel's one
|--- forum // directory for forum files
|------ index.php // Forum's one
....
Using this structure, URL is not rewritten to Laravel's routing index.php file.
If I rename/remove forum
folder URL is rewritten then.
使用这种结构,URL 不会被重写到 Laravel 的路由 index.php 文件中。如果我重命名/删除forum
文件夹 URL 将被重写。
Does it work for you?
对你起作用吗?
回答by Ramin
I needed to exclude /billing url on Laravel 5.7 So this way worked for me:
我需要在 Laravel 5.7 上排除 /billing url 所以这种方式对我有用:
Route::redirect('/billing', '/billing');
when billing located at: My billing folder location
计费时位于: 我的计费文件夹位置
回答by Giang Nguyen
I'm using nginx, it's work for me:
我正在使用 nginx,它对我有用:
location /your_folder {
try_files $uri $uri/ /your_folder/index.php?$args;
}