美文网首页
使用.htaccess实现apache URL重定向无效解决办法

使用.htaccess实现apache URL重定向无效解决办法

作者: 今後次 | 来源:发表于2018-11-14 12:40 被阅读125次

前言

一个服务器迁移项目,想要实现返回固定值的一个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

现象

  • 成功


    url中显示php后缀

    但是不想显示最后的php后缀。

  • 不成功


    url中不显示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>

相关文章

  • 使用.htaccess实现apache URL重定向无效解决办法

    前言 一个服务器迁移项目,想要实现返回固定值的一个API。采用php实现固定返回值。但是不想url中指定php文件...

  • .htaccess文件使用

    1、.htaccess文件使用前提 .htaccess的主要作用就是实现url改写,也就是当浏览器通过url访问到...

  • 页面重定向

    本域名内实现目录重定向 利用php文件中的header 跳转到指定页面 使用.Htaccess文件实现301重定向...

  • Typecho 伪静态设置方法

    typecho-url-rewrite Linux Apache 环境(.htaccess) Linux Ngin...

  • nginx-9 转换rewrite规则

    重定向到主网站 那些在共享主机期间只使用Apache s .htaccess文件配置所有内容的人,通常会将以下规则...

  • 301重定向到https 并且不带www跳转到带www

    Apache环境下,.htaccess 伪静态让http 301重定向到https, 并且不带www跳转到带www...

  • laravel安装

    安装composer 安装laravel 安装 修改权限 开启url重定向 apache服务器 加载重定向模块: ...

  • CI

    一、 url中去掉index.php Apache环境下,在项目目录下新建.htaccess文件,内容设置为 修改...

  • Asp.Net Core Url Rewrite

    在《Asp.Net Core Url Redirect》中使用重定向解决Url问题,还是有些不理想:重定向的Url...

  • apache .htaccess 带参数重定向方法

    我们平时遇到需要将固定的地址之间重定向,下面就是最好的方法: 这样访问home.php?mod=spacecp&a...

网友评论

      本文标题:使用.htaccess实现apache URL重定向无效解决办法

      本文链接:https://www.haomeiwen.com/subject/fnndfqtx.html