apache RewriteRule问题

apache RewriteRule问题

我想测试 test.com,如果在请求中找到某个文件,则提供该文件;如果找不到,则继续执行其余规则。我无法让它始终如一地执行此操作。

重写规则 ^/test.com /var/www/html/index.html [NC,L]

答案1

^ 表示行/字符串的开始,因此请求http://example.com/test.comhttps://www.example.com/test.com_with_more应该匹配,但是http://example.com/in_front_test.com不匹配。尝试删除 ^ 并在 . 前添加 \ ,这样它就可以匹配 . 而不是任何字符

RewriteRule test\.com /var/www/html/index.html [NC,L]

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule被用作参考。

相关内容