user311129
user311129

Reputation: 23

.htacces RewriteRule server error 500

I have this

RewriteRule ^(.*) public/$1    [NC,L]

in my .htacces file and i get Internal Server Error 500 Can someone help me?

And explain why do i get it.

Upvotes: 1

Views: 1431

Answers (1)

LazyOne
LazyOne

Reputation: 165088

Because you wrote your rules in such way that they create infinite rewrite loop which Apache has to break at some point, hence the 500 Internal Server Error. If you check your error log you will see exact error message.

The [L] flag does not necessary mean "rewrite done" -- it just means "rewrite done on this iteration -- lets go again from start".

Very useful to read: RewriteRule Last [L] flag not working?

To solve your problem -- you need to add some condition so that already rewritten rules are not get rewritten again and again. These rules should do the job for you (one of the possible solutions -- it all depends on how your actual project is set up):

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]

With this rule if URL is already rewritten or starts with /public/ straight away then no additional rewrite will occur.

Upvotes: 2

Related Questions