Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excluding a directory from using the route? #67

Open
unikoca opened this issue Nov 28, 2022 · 5 comments
Open

excluding a directory from using the route? #67

unikoca opened this issue Nov 28, 2022 · 5 comments

Comments

@unikoca
Copy link

unikoca commented Nov 28, 2022

Hi,

On a particular project, i'm using your library on the root of the domain, everything works fine.
But now, they install a folder ( ex: /abc/ ) that doesn't need to be managed by your routing.
Is there a way to 'exclude' a folder from your routing?

Regards,

@ibnsultan
Copy link

From what I know traditional routes should also work fine, let say you have file feature.php in folder abc

domain.com/abc/feature.php should also work

@unikoca
Copy link
Author

unikoca commented Nov 28, 2022

It's doesn't seems to work in my case, since everything is passing thru index.php (router) already, loading config, etc... within the htaccess file. Some conflics occurs.

i may put the entire routing in a if/else statement but it's not very clean... Better ways are welcome. 👍

@steampixel
Copy link
Owner

Requests to existing files and folders should be delivered directly without going through the index.php. There are rules to achieve this inside the .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

You can test this rules: Place a file (test.txt) into your root folder and try to call it: https://mydomain.com/test.txt
You should then see its contents.
Also you can place such a file into your sub folder and then call https://mydomain.com/abc/test.txt
Both request should bypass the router. If this does not work you should check your .htaccess file. Maybe it was modified?

@unikoca
Copy link
Author

unikoca commented Jan 11, 2024

I think I wasn't clear enough... I'm not talking about accessing a particular file within the /abc/ folder.

  1. let's say i use the regex '/([a-z0-9-/]*)' on the root of my applicaiton. It will grab /asd/sss/... and so on.
  2. now I want to 'exclude' a particular path that could be included in the first regex. (ex: /admin/...). I don't want the use a routing at all for this path.

note that the first regex will glab all the possible paths & files on the root and the subfolders. It is useful when you create folders from an admin panel for example.

could be useful to have an 'exclude' method to remove a file/path from the possibilities.

@ibnsultan
Copy link

3 ways you can achieve that @unikoca

  1. use of regexp: ^(?!.(?:admin|other_word|yet_another)).[a-zA-Z0-9-/]+.*$ (Recommended)
Route::add('/(^(?!.*(?:admin|other_word|yet_another)).*[a-zA-Z0-9-/]+.*$)', function() {
  return 'admin and some words not allowed';
});

You can even go further to define which words to begin with in your route

  1. add another parameter function of type array or string on the add function, and handle any words or expressions you don't want on the specific route

  2. If you're using Apache web server, use .htaccess to set custom rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants