RewriteBase - 将我带到同一目录?
RewriteBase - leads me to same directory?
我用下面的 htaccess 为自己构建了一个小型 MVC
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?controller= [QSA,L]
当我现在点击 link http://example.com/mycontroller/
时,我进入控制器 mycontroller
.. 这里一切正常。
但在 http://example.com/mycontroller/
里面我有更多的 link 也就是 http://example.com/mycontroller/edit/1
这导致我 http://example.com/mycontroller/mycontroller/edit/1
(?)
怎么可能?我该如何解决这个问题?
你的 HTML 中的链接是什么样子的?
<a href="/mycontroller/edit/1" ...
或 <a href="mycontroller/edit/1" ...
?
后者是相对于当前路径的,当你已经在/mycontroller/
时,它将扩展为/mycontroller/mycontroller/edit/1
要解决此问题,您需要使链接相对于服务器(即以 /
开头)
我用下面的 htaccess 为自己构建了一个小型 MVC
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?controller= [QSA,L]
当我现在点击 link http://example.com/mycontroller/
时,我进入控制器 mycontroller
.. 这里一切正常。
但在 http://example.com/mycontroller/
里面我有更多的 link 也就是 http://example.com/mycontroller/edit/1
这导致我 http://example.com/mycontroller/mycontroller/edit/1
(?)
怎么可能?我该如何解决这个问题?
你的 HTML 中的链接是什么样子的?
<a href="/mycontroller/edit/1" ...
或 <a href="mycontroller/edit/1" ...
?
后者是相对于当前路径的,当你已经在/mycontroller/
时,它将扩展为/mycontroller/mycontroller/edit/1
要解决此问题,您需要使链接相对于服务器(即以 /
开头)