Apache - 重写规则"$(.*)^"模式不适用于空请求



我试图做一些URL重写与Apache2和PHP,问题是,我做了一个。htaccess文件使用rewrite_mod,这里是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ webroot/index.php [QSA,L]

^(.*)$模式应该匹配所有内容,但它不匹配空请求,我不知道为什么。

给你一个例子,这里/root文件夹是。htaccess文件所在的地方。

    请求/root/anything匹配;
  • 请求/root/some/thing也匹配;
  • 请求/root/不匹配

在这里,/root/请求应该匹配,因为模式^(.*)$表示"匹配从0次到任意次数的任何字符"。

有人知道为什么它不匹配空请求吗?

我目前在Linux Mint下运行LAMP

你的规则是这样的:

RewriteEngine On
# handles landing page
RewriteRule ^/?$ webroot/index.php [L]
# handles rest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . webroot/index.php [L]

mod_dir模块如果在mod_rewrite之前运行,并将DirectoryIndex处理程序添加到登陆页面,即/index.php,因此由于RewriteCond %{REQUEST_FILENAME} !-f条件阻塞了规则的执行。

最新更新