我发现了一个与此类似的问题,但似乎对我不起作用(Make web root folder a sub-folder with .htaccess?)。因此,在找不到任何问题的答案后,我寻求帮助——我花了 2 个小时在 stackoverflow 上浏览了 200 多页的结果,然后才放弃。无论如何...
我正在创建一个小型 CMS,并且我的目录结构设置如下:
application
-- html
-- -- public
-- -- -- theme
-- -- -- -- css
-- -- -- -- images
-- -- -- -- js
-- -- -- forum
-- -- -- -- index.php
-- -- -- -- viewforum.php
-- -- -- -- viewthread.php
-- -- -- -- comment.php
-- -- -- index.php
-- -- -- login.php
-- -- -- profile.php
-- -- admincp
-- -- -- theme
-- -- -- -- css
-- -- -- -- images
-- -- -- -- js
-- -- -- index.php
-- -- -- manage.php
-- -- -- users.php
-- -- -- settings.php
-- plugins
library
我想要完成的是将 mydomain.com/application/html/public/index.php 映射到 mydomain.com/index.php 并使用 admincp 映射其 mydomain.com/admincp/index.php。这样看起来公共目录中的所有内容都位于根目录中。
目前,当我查看 mydomain.com 时,它显示来自 ../public/ 的 index.php 文件,但是当我尝试 mydomain.com/index.php 时,我得到一个未找到的错误。当我转到 mydomain.com/admincp 或 mydomain.com/admincp/manage.php 时,它可以工作——如果你知道一种使它更好的方法,请告诉我。:)
RewriteEngine on
RewriteRule ^$ application/html/public/
#RewriteRule ^(.*)$ application/html/public/$1 # Breaks site
RewriteCond %{DOCUMENT_ROOT}/admincp !-f
RewriteRule ^admincp/(.*)? application/html/admincp/$1
RewriteRule ^admincp$ admincp/ [L]
如果我能在这个问题上得到任何帮助、建议和讽刺,我将不胜感激。
- 编辑 -
@Michael 为我提供了一个符合我目的的答案结果如下:
RewriteEngine on
# Don't need this...
#RewriteRule ^$ application/html/public/
# Need [L] and a RewriteCond
# Don't do the rewrite if this is an actual existing file
# such as what is rewritten into application/html/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# And don't write admincp into public
RewriteCond %{REQUEST_FILENAME} !admincp
# With the above conditions met, write anything else into the public dir
RewriteRule ^(.*)$ application/html/public/$1 [L]
# Then just write admincp into application/html/admincp
RewriteRule ^admincp/(.*) application/html/admincp/$1 [L]
现在我只需要修复查看根目录时显示我的目录索引的问题--mydomain.com/
- 编辑 -
当我重新添加时
RewriteRule ^$ application/html/public/
它并没有中断,所以它看起来像它应该的那样工作!