gpt4 book ai didi

.htaccess - 如何构建 Laravel .htaccess 以直接指向公共(public)文件夹并删除 index.php

转载 作者:行者123 更新时间:2023-12-02 05:04:07 25 4
gpt4 key购买 nike

我正在尝试创建可在开发和生产服务器上使用的 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(在 url 中隐藏 public/index.php 以防止重复 url)
  3. 访问 http://example.com/X/X(X 是任意值)
  4. 重定向到 http://example.com/public/index.php/X/X(在 url 中隐藏 public/index.php 以防止重复 url)
  5. 防止访问公用文件夹外的目录/文件,并防止访问公用文件夹中的目录,但不访问文件。
  6. 无需在生产和开发之间更改配置

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

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

最佳答案

看看一个可能的选项 here .

关于.htaccess - 如何构建 Laravel .htaccess 以直接指向公共(public)文件夹并删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com