2017-04-26 68 views
1

每当我试图用.htacess隐藏.php分机号码并使用.php分机号码转到一个页面时,屏幕上显示的所有内容都是“Page Not Found”。我以前完美的工作,但我最近更改了托管公司,现在我使用Plesk Onyx 17.0.17CentOS Linux 7.3.1611PHP 7.1.4.htaccess隐藏分机号码

这里是我的.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 
+0

是使用Apache或nginx的吧。如果它使用nginx,则此文件不执行任何操作。 –

+0

@AndrewRayner'mod_rewrite'是一个'Apache'模块 –

+0

@PedroLobito正确,但他表示在切换主机时停止工作。这意味着,如果他以前使用Apache。这将工作。 –

回答

1

我现在的工作多亏Anubhava's答案上this question。我仍然不知道为什么我的老人可能不会工作。

这里是我用来解决该问题的代码:

## 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]