【发布时间】:2013-09-27 17:55:29
【问题描述】:
我有一个自定义网络应用程序,文件结构如下:
/apps/calendar/frontend/index.php
/apps/calendar/frontend/view/index.php
/apps/calendar/backend/index.php
/apps/calendar/backend/edit/index.php
/apps/calendar/backend/add/index.php
/apps/calendar/backend/view/index.php
我正在尝试编写一个 .htaccess 文件来帮助重定向文件,这样他们就看不到“真实”路径。
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^([^/\.]+)/(.*)/(.*)($|/$) /apps/$1/frontend/$2/$3 [NC,L]
RewriteRule ^([^/\.]+)/(.*)($|/$) /apps/$1/frontend/$2 [NC,L]
RewriteRule ^([^/\.]+)($|/$) /apps/$1/frontend/ [NC,L]
当我访问 localhost/calendar 时,它应该将重定向映射到 /apps/calendar/frontend/index.php。但是当我访问 localhost/calendar/add 时,它会给我一个 301(永久移动),然后在控制台中显示 localhost/apps/calendar/frontend/add/index.php 的完整页面。任何人都知道为什么会发生这种情况?或者有更好的方法来解决这个问题?这些应用程序可能有大量的子目录,所以我并不是特别热衷于为永远的子目录组合制定规则。
你也可以看到我有一个 /admin 路径,它将加载应用程序的 /backend/ 部分。我会假设我可以用 /admin 的前缀做类似的代码?
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect