Disable Laravel Routing for a specific folder/route
Asked Answered
M

6

19

I'm wondering how to disable the routing on laravel for a specific directory?

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..?

Merlinmerlina answered 6/8, 2013 at 8:33 Comment(2)
Post your routes.php fileSlagle
@Slagle Could you help out?Merlinmerlina
P
15

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]
Parnassus answered 2/2, 2014 at 19:10 Comment(1)
This one works. Make sure you are updating .htaccess of the right directoryUnhallowed
Z
6

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

Zenaidazenana answered 25/6, 2014 at 16:16 Comment(0)
M
4

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.)

Marlo answered 7/8, 2013 at 5:24 Comment(1)
For me all the files in /public load normally without any changes to .htaccess. The problem is that something like /public/forum does not automatically load the index in that path anymore, it has to be accessed by /public/forum/index.php and the above rules does not help either. Any idea how to fix this?Euler
S
3

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?

Slagle answered 7/8, 2013 at 7:42 Comment(0)
M
2

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

Meal answered 1/1, 2019 at 22:56 Comment(0)
C
0

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

location /your_folder {     
    try_files $uri $uri/ /your_folder/index.php?$args;
}
Cranky answered 10/10, 2018 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.