前言
一个服务器迁移项目,想要实现返回固定值的一个API。采用php实现固定返回值。
但是不想url中指定php文件的话,可以正常显示。但是不想暴露最后的php后缀。
所以采用.htaccess进行重定向。实验后没有效果。
调查解决对策后,在此记录一下。
文件夹构成
- php内容
<?php
header('Content-type:text/plain;charaset=utf-8');
print "S00\r\n00000000\r\n0\r\n" ;
?>
- .htaccess内容
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
现象
-
成功
但是不想显示最后的php后缀。
-
不成功
解决策
在apache的配置文件httpd.conf中修改如下(★★★的位置)。
apache httpd2.4的情况配置文件路径
/opt/rh/httpd24/root/etc/httpd/conf/httpd.conf
修改内容:
# Further relax access to the default document root:
<Directory "/opt/rh/httpd24/root/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# [http://httpd.apache.org/docs/2.4/mod/core.html#options](http://httpd.apache.org/docs/2.4/mod/core.html#options)
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#修正前AllowOverride None
#修正后★★★
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>