我设置了以下重写规则
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/