Mod_rewrite Adds the .php extension

My .htaccess file looks like this:

Options -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

The problem I am facing is that when I try to access my site without www. the prefix, the .php extension is added to the address, which can often cause a problem. For example, if I try to access my homepage with the address example.com, this address will be converted to www.example.com/.php. I want www. to add, but the .php extension added at the end causes an error. How to fix it?

+5
source share
2 answers

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Remove L in [R=301,L], which means "Last", which means "stop processing RewriteRules after that."

301 " ". . , , URL- ? .

+1

"L" 4 "", .. . L.

0

All Articles