【问题标题】:Installing a Zend project on hosting with access only to the public directory在主机上安装 Zend 项目,只能访问公共目录
【发布时间】:2012-01-14 21:21:23
【问题描述】:

我在 Ubuntu 上开发了一个 Zend Framework 项目。我在本地机器上创建了一个虚拟主机进行测试。它在我的本地机器上运行良好。这是本地机器上虚拟主机的入口。

<VirtualHost *:80>
    ServerName example.dev
    DocumentRoot /var/www/example/public/
    <Directory /var/www/example/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

问题:

我的问题是,当我购买域名(example.com)名称和托管时,他们给了我以下 ftp 目录来上传我的内容。

example.com 指向/www.example.com/web/content

但我需要example.com 指向/www.example.com/web/content/public

我要求他们解决它,但他们说这是不可能的。是否有任何编程/配置解决方案。

谢谢

编辑:

我已经在/www.example.com/web/content/public关注.htaccess

SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

【问题讨论】:

  • 我确信有一些解决方法,而且我确信会有一些解决方法。不过,一般来说,没有可能在 Web 根目录之外拥有目录的 Web 托管并不是很好。根据他们的其他功能是什么,这会让我考虑寻找另一个供应商
  • @Pekka:谢谢。如果我放置一个 index.php 文件 /www.example.com/web/content 并将其重定向到该 index.php 中的 /www.example.com/web/content/public。这是一个好的解决方案吗?它会起作用吗?
  • 我对 Zend MVC 不够熟悉,无法回答这个问题。我想您应该能够更改项目中的 .htaccess 文件,以便它在内部进行重定向,但在外部,public/ 仍然不可见。我确定有这方面的资源,但我不知道在哪里
  • 我已经在/www.example.com/web/content/public 中有.htaccess 文件。此.htaccess 文件用于将example.com/index.php/person/profile 更改为example.com/person/profile(例如)。
  • 请参阅stackoverflow.com/a/3765443/131824 了解解决此常见问题的方法列表。

标签: php zend-framework ftp dns hosting


【解决方案1】:

根据他们使用的 Web 服务器和他们的配置,您可能能够覆盖某些配置,例如,您可以使用 apache 重写规则更改文档根目录,并将 .htaccess 文件放在下面/www.example.com/web/content的根

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteRule ^$ /public/index.php [L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

【讨论】:

  • 很好的答案,但我不建议将它放在 .htacess 中,因为它是性能杀手。 .htaccess 文件中写入的规则不能被 apache 缓存,服务器必须为每个请求扫描文件。如果将 .htaccess 规则移动到虚拟主机配置文件中,规则将被缓存并且 apache 性能会有所改善。
  • @Flukey 公平点,但在这种情况下,它是共享主机,所以这是不可能的
  • @Pekka 啊,确实。耻辱:-(
  • @Jean-Christophe Meil​​laud:谢谢。当我将 .htaccess 放在内容文件夹中时,它成功显示了索引页面,但是当我单击索引页面上的任何链接时,它显示以下错误:Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Apache/2.2 Server at example.com Port 80
  • 我在上面的问题中添加了我当前的公用文件夹 .htaccess 文件内容。我需要更改此文件中的任何内容吗?谢谢
【解决方案2】:

将 index.php 文件放入 public 文件夹 并将 .htaccess 放在根文件夹中,巫婆内容

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

Options -Indexes

【讨论】:

    【解决方案3】:

    这很简单,只需将公共目录内容移动到父目录,以便 /www.example.com/web/content/public 中的所有文件 开启 /www.example.com/web/content

    不要忘记编辑 index.php 文件中的包含路径以使用新位置

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多