Răzvan T.
Răzvan T.

Reputation: 360

Allow specific URL in htaccess even if htaccess rewrites a word from that URL

I have the following situation in my .htaccess:

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

This is specifically made to not allow people to visit my laravel directory. However, I want to be able to load a specific file from laravel directory into other files, like this:

<script src="/laravel/public/js/app.js" defer></script>

The problem is the following: The generated URL will have 'laravel' removed from it as per the rule. If I comment that rule, then that line of code that includes app.js will work.

I have tried several things with my .htaccess and searched for a solution, but alas, I am failing to understand, it seems, how .htaccess code really does the things.

Can anyone help with a rule to allow specifically that URL? Or, if possible, to allow access to the /laravel/public/js/ directory without removing the word 'laravel' from the URL.

Thank you very much!

Upvotes: 0

Views: 148

Answers (1)

C3roe
C3roe

Reputation: 96226

Instead of doing complex things with checking negated patterns in a RewriteCond or similar, you could just put a rule before this that matches that URL specifically, does no rewriting at all (- in place of substitution URL), and then uses the L flag to indicate that none of the following rules should be evaluated any more.

RewriteRule ^laravel/public/js/app\.js$ - [L]

Upvotes: 2

Related Questions