Error .httaccess

I created a .htaccess, with the following rules:

RewriteEngine on
RewriteBase /

RewriteCond% {THE_REQUEST} public / ([^ \ s?] *) [NC]
RewriteRule ^% 1 [L, NE, R = 302]
RewriteRule ^ ((?! public /).*)$ gamenews / public / $ 1 [L, NC]

error 500 is happening, is there any harmful rule? if there is what I can do to replace it.

obiservation: it is an api that uses the composer with all the pre-installed dependencies

Hello there,

That could be because that htaccess rule is invalid.
Please check this Knowledge Base article out:

3 Likes

Hello Diego!

First, what you want to do with this rules?

For starters, you should look at your use of whitespace within the rules. Code in general, and .htaccess rules especially, are sensitive to use of whitespace. So RewriteCond% ... should be RewriteCond %..., the flags should be [L,NC] and not [L, NC], and the behavior of regular expressions also changes if you add or remove spaces.

1 Like

ok, but how would I make the .htaccess valid I’m starting and I don’t know where I can get the errors.

So, the correct htaccess code should (or may) be like this:

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ gamenews/public/$1 [L,NC]
2 Likes

Unfortunately, .htaccess files don’t have error messages or logs. They either work or they don’t. You can selectively comment or uncomment rewrite rules/blocks to figure out which cause your site to crash and which ones don’t.

Or you could go back to the software you’re trying to install and double check you’re copied their .htaccess rules correctly.

5 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.