简体   繁体   English

无法使用 .htaccess 从文件扩展名中删除 .php

[英]unable to remove .php from file extension with .htaccess

I have the following in my .htaccess file.我的 .htaccess 文件中有以下内容。 Redirecting the www.重定向 www. works perfectly, as does the custom 404 message.完美运行,自定义 404 消息也是如此。 The removal of .php from the file extension fails to work.从文件扩展名中删除 .php 失败。 domain.com/file returns the 404 message, with domain.com/file.php working fine. domain.com/file 返回 404 消息,domain.com/file.php 工作正常。

RewriteEngine On
RewriteBase /

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

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

#
ErrorDocument 404 /404.php

Also if it helps this is in my 000-default.conf file此外,如果它有帮助,这在我的 000-default.conf 文件中

<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Write the code in .htaccess file in your project folder.it might be help for you将代码写入项目文件夹中的 .htaccess 文件中。它可能对您有所帮助

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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