Search code examples
.htaccessinternal-server-error

“Internal Server Error ” on invalid pages


Some lines of my htaccess file will be look like as follows

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.images$  
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_URI} !(\.jpg|\.gif|\.png)$ [NC] 
RewriteRule ^(.*)$ user/$1 [L,QSA]

But when I go for a invalid url, so for mydomain.com/blablabla ,it's giving Internal Server Error. Is anything wrong with my .htaccess


Solution

  • Try adding these conditions right after RewriteCond %{REQUEST_URI} ^/(.*)$

    RewriteCond %{DOCUMENT_ROOT}/user/%1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/user/%1 -d
    

    This checks if the rewritten URI would exist, if it doesn't, it won't do the rewrite, which is causing an internal loop if the URI doesn't exist.