Rewrite engine causes huge error

important is, that when I write some rewrite conditions in my .htaccess it outputs this:

After some research, I found out the reason. This is a code that removes the PHP extension.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

The problem is the first line, but when I delete it, the page will work, but the whole code won’t. I’m not sure if the code is fine, but the RewriteEngine seems to be a problem. Are there any solutions out there?

Final Code
php_value display_errors On
php_value mbstring.http_input auto
php_value date.timezone America/New_York

DirectoryIndex router.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

This will work:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

This also will work in sub-directories without pointing RewriteBase to them

There is a far easier way to disable file extensions on this hosting by just using:

Options +MultiViews

So you mean that the first line shouldn’t be there at all, and the code I’ve been using is just written wrong, right? That would make it clear a lot.

That’s a very helpful and short code! It works just amazing. Could I please ask where did you find this solution @TigerMANEK426?
I’m also looking for a non-www force and file blocking, that isn’t working for me either.

non-www force
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
file blocking

RewriteCond %{HTTP_REFERER} https://%{HTTP_HOST}%{REQUEST_URI} [NC]
RewriteRule .(gif|jpg|png|css|svg)$ [R,L]

Try this


I found the code on Google.

When say “non-www force”, do you mean its the users choice to have www. at the start or not?

1 Like

I mean to block www at the start. So if you go to it will redirect you to

Ah, okay. Use this code:

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
1 Like

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