【问题标题】:How to structure Laravel .htaccess in order to point straight to public folder & remove index.php如何构建 Laravel .htaccess 以直接指向公共文件夹并删除 index.php
【发布时间】:2012-11-16 17:55:15
【问题描述】:

我正在尝试创建可在开发和生产服务器上使用的 htaccess 文件。开发服务器的文件夹结构是这样的:

Server Root (www)
 -laravel
  -public
   -index.php
    -controller/method... etc

生产服务器没有不可公开访问的文档根目录。我在 appfog 上部署它,它需要 .htaccess 来执行此操作。 Appfog 的文档中提到了这一点:https://docs.appfog.com/languages/php#custom

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

生产服务器的文件夹结构将是这样的(它只是删除了 laravel 文件夹):

Server Root (www)
 -public
  -index.php
   -controller/method... etc

我想在不使用apache httpd的情况下实现这一点,只使用htaccess,因为开发环境会不断变化。

我希望能够做到这一点:

  1. 访问http://localhost/laravel/X/X(X 代表任何东西)
  2. 被重定向到http://localhost/laravel/public/index.php/X/X(将public/index.php隐藏在url中以防止重复url)
  3. 访问http://example.com/X/X(X 代表任何东西)
  4. 被重定向到http://example.com/public/index.php/X/X(将 public/index.php 从 url 中隐藏以防止重复 url)
  5. 禁止访问公用文件夹外的目录/文件,并禁止访问公用文件夹中的目录,但不能访问文件。
  6. 无需在生产和开发之间更改配置

问题是,我该怎么做?我需要多少个 .htaccess 文件?

到目前为止,我的进度一直在阅读 laravel 文档和此论坛帖子,但无论我做什么,当我转到 http://localhost/laravel/ 时,我总是收到 404 或 500 服务器错误

【问题讨论】:

    标签: .htaccess environment-variables environment laravel clean-urls


    【解决方案1】:

    看看一个可能的选项here

    【讨论】:

    • 你好Mogetutu,你的回答没有回答我的问题。我无法使用虚拟主机。
    • 我完全误解了你的问题 在你的 .htaccess link987654322@
    【解决方案2】:

    您将把它放在应用程序的根目录中。

    - application/
    - public/
      - .htaccess (already provided by laravel)
    - index.php/
    - .htaccess (the one specified by appfog)
    

    一切正常。

    【讨论】:

      猜你喜欢
      • 2013-10-01
      • 2019-06-27
      • 2014-03-24
      • 1970-01-01
      • 2017-10-29
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      相关资源
      最近更新 更多