windows - Mod_rewrite 在 Windows 和 Ubuntu 上有不同的结果

标签 windows linux .htaccess mod-rewrite ubuntu

我设置了以下重写规则

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ core/index.php [L]

网站架构是

newsite
 ﹂ .htaccess
 ﹂ core
     ﹂ index.php

如果我在 Windows 上使用网址:http://localhost/web/newsite/test
它将重定向到 /web/newsite/core/index.php
它起作用了!

但如果在 Ubuntu 上使用 url http://localhost/~user1/web/newsite/test
它将重定向到 /home/user1/public_html/web/newsite/core/index.php
不是 /~user1/web/newsite/core/index.php

那么,如何解决这个问题呢?
谢谢!

最佳答案

在规则上方添加一个RewriteBase:

RewriteBase /~user1/web/newsite/

Ubuntu 上的 Apache 会尝试猜测重写规则的目标是 URI 路径还是文件路径,但它的猜测不正确,因此您必须告诉它真正的相对 URI 基础是什么。

关于windows - Mod_rewrite 在 Windows 和 Ubuntu 上有不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12657401/

相关文章:

linux - Linux 中的 Clojure - REPL 以不同的用户运行?

c - 为什么缓存不能正常工作?

php - 自定义 404 错误页面——仅适用于 PHP 页面

.htaccess 重定向,如果 url 中的文件夹名称

windows - cmd 和感叹号

windows - 如何将 Windows 更新设置为从不使用 PowerShell 检查更新?

linux - 通过 VPN : connection timed out SSH 到在 VPC 中的私有(private)子网中运行的 EC2 实例

php - 正则表达式匹配.htaccess中的一系列文件类型

php - 启用 APC 后页面超时

c++ - 使用 Windows API 获取键盘输入的更好方法?