【问题标题】:How to use apache rewrite to rewrite all traffic from /admin/recurring/foobar/123 to /admin/recurring/public/foobar/123如何使用 apache rewrite 将所有流量从 /admin/recurring/foobar/123 重写为 /admin/recurring/public/foobar/123
【发布时间】:2016-09-23 23:05:57
【问题描述】:

我刚刚将 laravel 安装到 /admin/recurring 但后来我发现所有的商品都是公开的/ 如何将所有流量指向 /admin/recurring/foo/bar/123 将请求实际调用到 /admin/recurring/public/foo/bar/123

这是我尝试过的:

<IfModule mod_rewrite.c>
    RewriteEngine On

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #This last condition enables access to the images and css folders, and the robots.txt file
    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
    RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>

但这不起作用。它给了我一个抱歉,找不到您要查找的页面。在 Laravel 5.3 中

【问题讨论】:

  • 您不需要对 htaccess 文件进行任何更改。 public 下的 Index.php 已经设计用于处理请求。您需要做的就是将您的域指向公共文件夹(等... /admin/recurring/public)。然后你可以定义你所有的路线,这里解释laravel.com/docs/5.3/routing
  • 我做不到,我有一个完整的网站围绕它
  • 如果有帮助请查看此帖子laravel.io/forum/…
  • @H.Kontodios 我检查了它,但我没有看到明确的答案。虽然内容丰富。
  • FallbackResource /admin/recurring/public/index.php 有点像 laravel,但问题是 laravel 在compiled.php 中显示 NotFoundHttpException

标签: php apache .htaccess laravel mod-rewrite


【解决方案1】:

mod_rewrite 不需要这样做。相反,您应该:

<Directory /path/to/admin/recurring>
  FallbackResource /admin/recurring/public/index.php
</Directory>

(注意:这假设您运行的是至少 2.2.16 或更高版本。您应该是。2.4 已经推出近 5 年了。)

另外,如果这是在 .htaccess 文件中,您只需要 FallbackResource 行,在 /path/to/admin/recurring/.htaccess

【讨论】:

    【解决方案2】:

    你会试试这个并检查它是否有效? 在目录标签中添加 /admin/recurring 的完整路径。

    <Directory "/admin/recurring">
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ public/index.php/$1 [L]
        </IfModule>
    </Directory>
    

    【讨论】:

    • 好吧,我在 admin/recurring/.htaccess 中使用了一个 .htaccess 文件,我在 RewriteCond %{REQUEST_FILENAME} 上复制了 RewriteEngine !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^( .*)$ public/index.php/$1 [L] 但什么也没发生
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    相关资源
    最近更新 更多