Disable Laravel Routing for a specific folder/route

萝らか妹 提交于 2019-12-01 15:46:41

I had to add this line in public/.htaccess

RewriteCond %{REQUEST_URI} !^/foldername

before this line (that redirects trailing slashes)

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

With Laravel 4 none of these solutions were working for me. I eventually solved it by placing

RewriteRule ^(directory-name) - [L]

before

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

in public/.htaccess

You need to make an exclusion in your .htaccess file. Just above the rule that sends everything to index.php, add this:

RewriteCond %{REQUEST_URI} !^/forums

Anything that begins with /forums will not be sent to Laravel.

(Of course, this is assuming you are using Apache.)

According to your routes.php file it is supposed to work.

  1. You are not catching forum URL at all
  2. If 'forum' directory/file exists, URL is not rewritten to Laravel's index.php

routes.php (I used this one in the test case)

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.

Does it work for you?

I'm using nginx, it's work for me:

location /your_folder {     
    try_files $uri $uri/ /your_folder/index.php?$args;
}

I needed to exclude /billing url on Laravel 5.7 So this way worked for me:

Route::redirect('/billing', '/billing');

when billing located at: My billing folder location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!