Redirects with role not working as intended

Im using netlify identity to protect
the index file in the log folder also loads a script located in the same folder but its not loading when im loggin in and i try to acces the /log path.

my _redirects file contains the following code, and should work according to the documentation
/log/* 200! Role=admin

but to make it work i have to load the script from this url:
<script src=""></script>
instead of
<script src="script.js"></script>

shouldn’t this work with only script.js as the source, instead of the full url, since i added a * to the redirects file?

hi there, before we dig in, did you see this brand new guide on debugging redirects?

I strongly suggest you give it a thorough read through and see if this fixes your problem:

if not, please post again, and we’ll try and troubleshoot.

Yes i already read it. It even says:

  • Use an asterisk, in order to gate access to an entire directory, e.g.
    /gatedpages/* 200! Role=admin

so it should technically work

Hey there, @Fabian9799

It looks like this thread has been a bit quiet since you last posted. Are you still encountering this issue? If so, what additional debugging steps have you taken?

Let us know!

I tried all different combinations that were in the documentation but none of them worked for me. Is there a example somwhere which protects a page which loads a script from a folder?

Thanks for your patience! I just looked in our database and we do seem to have deployed the redirect that you are debugging:

"from path" => "/log/*" "to path" => "/log/:splat", "status" => 200, "force" => true, "conditions" => { "Role" => "admin" }

That redirect looks reasonable to me. I don’t understand any reason why the load of /log/script.js would be different from a load of script.js from /log/index.html .

Can you show me the HTML page that has the link that doesn’t work, so I can see the code and where it is called from?


Thats how it looks currently:
The log folder is located in the root of the entire repo

and the redirects file has only those 2 lines:
/img/fabian9799.png /assets/img/fabian9799.png
/log/* 200! Role=admin

What happens if you try <script src="/script.js"></script>?

Perhaps <script src="./script.js"></script>?

A little tricky given it’s gated but we’ll work it out :muscle:.

1 Like

I tried both methods. Its always linking to the script.js file on the root of the repo and not the one in the folder

Oh, hang about – that means it’ll need to be /log/script.js because the .js file isn’t at root.

/log/index.html is served as /log (file), so you’ll still need to go in to /log/ (directory) to request the asset.

That worked.Thanks for the help.
Its just a little bit confusing for me why its not working with only the filename, since it should normally work since its in the same folder and it works on other non gated pages

1 Like

Heh, I don’t blame you for thinking this :slight_smile:

/log/index.html is in fact served as /log – rather than being exposed as a file called index.html under the /log directory, it’s a file called log under the / directory.


…if what you’re seeing is that you have, for example, /test/index.html which isn’t gated and doesn’t need to reference /script.js as /test/script.js please let me know :smiley:

1 Like