【问题标题】:.htaccess to have index.php and assets inside a public folder.htaccess 在公共文件夹中拥有 index.php 和资产
【发布时间】:2015-10-20 17:57:15
【问题描述】:

我想让我的项目树像这样划分:

  • 应用
  • 公开
    • 资产
    • index.php
  • 系统

我应该有两个 .htaccess 文件(一个在 root 中,另一个在 /public 中)还是只有一个?

我的项目在 URL http://localhost/my-project/

我已经将$system_path$application_path 指向它们的父文件夹,如下所示:

$system_path = '../system';
$application_folder = '../application';

但我可能会遗漏一些东西。

【问题讨论】:

  • 应用程序和系统文件夹是否在 Apache Web 目录中?他们需要吗?
  • 是的,他们是。路径是`C:\wamp\www\my-project`。我希望他们留在那里,因为我正在为这个项目组织我的 git 存储库。
  • 但是您是否在 Apache 中将C:\wamp\www\my-project 设置为您的DocumentRoot?我问的原因是,除非您在applicationsystem 中有任何需要由Web 客户端直接访问的内容,否则您应该简单地将DocumentRoot 定义为C:\wamp\www\my-project\public,那么您可以更好地保护您的底层应用程序逻辑从窥探的眼睛,也使你的问题没有实际意义。您仍然可以轻松地将您的存储库植根于my-project(无需更改)。
  • 好的,但这不是意味着我不能在这个 apache 服务器中拥有不同的项目吗? (我猜我们会谈论虚拟主机)
  • 这不会应用类似的东西。如果您在服务器上有其他项目,您可能只需为它们配置虚拟主机,并使用适当的DocumentRoot for 每个项目的公开可用资源。

标签: php apache .htaccess codeigniter wamp


【解决方案1】:

您的 目录中只需要一个.htaccess 文件,其条目如下:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ public/index.php/$1 [L]

【讨论】:

  • 刚刚尝试过,现在我收到 500 错误...根据 Apache 日志:Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary.
  • @LeandroDimitrio 使用它:RewriteCond %{ENV:REDIRECT_STATUS} ^$
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 2013-10-29
  • 1970-01-01
  • 2021-12-30
相关资源
最近更新 更多