简体   繁体   中英

Website index.php not displaying after edit to .htaccess

I made the following edit to .htaccess in order to hide the file endings.

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\.php
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Since making this edit, whenever I go to the to the top home-page eg example.com I get the following error-

The requested URL /.php was not found on this server.

Although this does work for my sub-pages eg example.com/about.php becomes example.com/about

The code you're looking for to remove the .php extension in the URL is this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM