mod_rewrite 适用于 '/test',但不适用于 '/'

发布于 2024-08-23 14:28:49 字数 412 浏览 2 评论 0原文

.htaccess 文件中的以下代码行为不正确。

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /test/$1 [L,QSA]

上面的代码将正确地将对“domain.com/uri-here”的请求发送到“/test/”目录。但是,对“domain.com/”的请求是不匹配/路由。

我不确定环境是否存在问题,尽管似乎是由于在另一台服务器上运行相同/相似的代码而导致的。

我做错了什么?

提前致谢!

The following code inside an .htaccess file is behaving incorrectly..

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /test/$1 [L,QSA]

The above will correctly send requests to 'domain.com/uri-here' to the '/test/' directory.. However, requests to 'domain.com/' are not matched / routed.

I'm unsure if there's an issue with the environment, though it seems so due to same / similar code working on another server.

What am I doing wrong?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光瘦了 2024-08-30 14:28:49

/ 可能与 RewriteCond %{REQUEST_FILENAME} !-d 匹配

/ is likely matching against RewriteCond %{REQUEST_FILENAME} !-d

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文