【问题标题】:Laravel Shared Hosting .htaccessLaravel 共享主机 .htaccess
【发布时间】:2023-03-31 17:17:02
【问题描述】:

我正在尝试将 Laravel 项目部署到共享主机上,我已经设法完成了大部分艰苦的工作,但我无法在没有 Forbidden 问题的情况下剥离 /public 目录。

网站工作并显示这些链接的相同页面

  • www.mywebsite.com/test/index.php
  • www.mywebsite.com/test/public/

但没有 /index.php 它返回 ->

Forbidden

You don't have permission to access /test/ on this server. 

目前我的 .htaccess 如下所示。

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]

</IfModule>

有什么想法吗?

【问题讨论】:

  • 所以www.mywebsite.com/test/public/ 有效但www.mywebsite.com/test/ 无效?
  • www.mywebsite.com/test/index.php 虽然有效,但我认为我的 .htaccess 有问题

标签: php apache .htaccess mod-rewrite laravel


【解决方案1】:

test/.htaccess中试试这个规则:

DirectoryIndex index.php
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /test/

    RewriteRule ^$ public/index.php [L]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

</IfModule>

【讨论】:

  • 感谢您的快速回复 :) 这种工作会在 index.php 显示网站时产生 NotFoundHttpException?
  • 是的,但是 www.mywebsite.com/test/index.php 有效,而且 www.mywebsite.com/test/public 有效
  • 未找到 - 在此服务器上未找到请求的 URL /test/index.php。
  • team-viewer 会更容易吗?
  • 不幸的是又一样了。
【解决方案2】:

这是我使用的魔法脚本(添加到public_html 中的.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

【讨论】:

  • 谢谢。它对我有用。尝试了很多东西。没有任何效果。
  • 如果在 web 服务器上它不工作,然后像这样添加 RewriteBase RewriteEngine On RewriteBase / RewriteRule ^(.*)$ public/$1 [L]
【解决方案3】:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/index.php [L]
    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

【讨论】:

  • 这看起来与最佳答案非常相似。为什么要这样做?
【解决方案4】:

这个脚本对我有用。

<IfModule mod_rewrite.c>
   RewriteEngine On
   # Force SSL
   RewriteCond %{HTTPS} !=on
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # Remove public folder form URL
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-02
    • 2011-12-05
    • 2018-06-21
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2018-11-14
    • 2018-10-21
    相关资源
    最近更新 更多