Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess隐藏页面扩展名_Php_.htaccess_Mod Rewrite_Plesk - Fatal编程技术网

Php .htaccess隐藏页面扩展名

Php .htaccess隐藏页面扩展名,php,.htaccess,mod-rewrite,plesk,Php,.htaccess,Mod Rewrite,Plesk,每当我试图用.htacess隐藏.php扩展名并使用.php扩展名转到页面时,屏幕上显示的都是“未找到页面”。我以前的软件工作得很好,但最近我更换了主机公司,现在我正在使用CentOS Linux 7.3.1611和PHP7.1.4的Plesk Onyx 17.0.17 以下是我的.htaccess文件的内容: Options -Multiviews -Indexes # Disable Automatic Directory detection DirectorySlash Off Err

每当我试图用
.htacess
隐藏
.php
扩展名并使用
.php
扩展名转到页面时,屏幕上显示的都是“未找到页面”。我以前的软件工作得很好,但最近我更换了主机公司,现在我正在使用
CentOS Linux 7.3.1611
PHP7.1.4
Plesk Onyx 17.0.17

以下是我的
.htaccess
文件的内容:

Options -Multiviews -Indexes

# Disable Automatic Directory detection
DirectorySlash Off

ErrorDocument 404 /!404.php

RewriteEngine On
RewriteBase /

# Remove trailing slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/+$ $1 [R=301,L]

RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

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

我现在有它的工作,感谢对答案。但是我仍然不知道为什么我的老朋友不能工作

下面是我用来解决这个问题的代码:

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

它使用的是apache还是nginx。如果它使用的是nginx,那么这个文件什么也不做。@AndrewRayner
mod_rewrite
是一个
Apache
module@PedroLobito是的,但他说当他更换主机时,它就停止工作了。这意味着如果他以前使用过apache。这当然有效。我正在使用Apache,可能还有Nginx。但是,我可以确认正在使用我的
.htaccess
文件,因为我已尝试对其进行更改,这是使自定义404页面正常工作的唯一方法。另外,由于.php扩展名,我认为无法使用HTTPS的
附加指令和
附加nginx指令来设置404页面,因此必须使用.htaccess来完成。如果我将垃圾放在
.htaccess
文件的顶部,我会得到一个500错误。但是,如果我注释掉这一行
RewriteRule(.*)index\.php/*(.*)/$1$2[R=301,NE,L]
,重定向仍然执行。