• 技术文章 >后端开发 >PHP问题

    php伪静态后html不能访问怎么办

    PHPzhongPHPzhong2020-09-25 14:01:31原创828

    php伪静态后html不能访问的解决办法:首先判断文件是否存在;然后设置存在则不rewirte,不存在且符合规则才rewrite;最后修改htaccess文件即可。

    推荐:《PHP视频教程

    具体问题:

    PHP伪静态后不能访问纯html文件

    .htaccess文件

    RewriteEngine on
    RewriteRule index.html$ index.php
    RewriteRule art.html$ project.php?file=art
    RewriteRule music.html$ project.php?file=music
    RewriteRule dance.html$ project.php?file=dance
    RewriteRule radio.html$ project.php?file=radio
    RewriteRule director.html$ project.php?file=director
    RewriteRule perform.html$ project.php?file=perform
    RewriteRule flight.html$ project.php?file=flight
    RewriteRule ([a-zA-Z]+)-([0-9]+).html$ page.php?pageid=$2
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([0-9]+).html$ page.php?pageid=$2&info=$3
    RewriteRule ([a-zA-Z]+)-([0-9]+)-rules-(.*)-([a-zA-Z]+).html$ page.php?pageid=$2&info=$3&file=$4
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+).html$ page.php?pageid=$2&menuid=$3&file=$4
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([a-zA-Z]+).html$ page.php?pageid=$2&file=$3
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([a-zA-Z]+)-list([0-9]+).html$ page.php?pageid=$2&file=$3&page=$4
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+)-list([0-9]+).html$ page.php?pageid=$2&menuid=$3&file=$4&page=$5
    RewriteRule ([a-zA-Z]+)-([0-9]+)-([0-9]+)-(.*)-([a-zA-Z]+).html$ page.php?pageid=$2&menuid=$3&artid=$4&file=$5

    而且我都已经把 RewriteRule index.html$ index.php 这句去掉了 但打开的时候 还是反问伪静态

    我现在要访问网站里的纯静态HTML文件,同时又要求PHP的伪静态也能访问,怎么做?

    解决办法:

    应该先判断文件是否存在,存在则不rewirte。不存在且符合规则才rewrite

    例如:文件或目录不存在则rewrite到index.php,否则直接读取存在的文件。

    <IfModule rewrite_module>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>

    以上就是php伪静态后html不能访问怎么办的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:php
    上一篇:php如何禁止列目录 下一篇:php下载文件无法打开怎么办
    大前端线上培训班

    相关文章推荐

    • php如何在不同页面之间传值• php怎么安装pdo_mysql扩展• PHP实现抓取百度搜索结果,并分析数据结构• php如何禁止列目录

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网