首页 > 解决方案 > Apache .htaccess 2 个方向

问题描述

我想设置一个 .htaccess,如果第一个条件匹配,apache 将使用 index.php,如果第二个条件匹配,则使用 index.html。

我正在尝试这样:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/anystring.*
RewriteRule . index.php

# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/anystring
# Otherwise forward it to index.php
RewriteRule . index.html

因此,如果请求 uri 以任何字符串开头,则为 index.php,否则为 index.html。

上面的代码不能这样工作,它有什么问题?

标签: phpapache.htaccess

解决方案


推荐阅读