Home >Backend Development >PHP Problem >What should I do if html cannot be accessed after php is pseudo-static?

What should I do if html cannot be accessed after php is pseudo-static?

PHPz
PHPzOriginal
2020-09-25 14:01:313069browse

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

What should I do if html cannot be accessed after php is pseudo-static?

推荐:《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>

The above is the detailed content of What should I do if html cannot be accessed after php is pseudo-static?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn