【问题标题】:Laravel application on sub-directory子目录上的 Laravel 应用程序
【发布时间】:2018-10-07 22:26:16
【问题描述】:

laravel 应用程序似乎与服务器上的 子目录 存在路由问题。 本地机器上正在运行的应用程序无法在实时服务器上的子目录中的临时域上运行。玩转.htaccess 似乎有不同的结果。

This question 几乎与我要寻找的相同,但他没有任何解决方案,而我有一些工作要做。

laravel public 中的 .htaccess 已修改为:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

RewriteBase /~timely/email-client  //<--base has been modified
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

The application 会将您重定向到host gator 404 page

我还添加了.htaccess 到主目录,这会将每个请求转发到public 目录。

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

删除 home/main 后,.htaccess 仅适用于 / 路由:例如

http://gator4057.temp.domains/~timely/email-client/public 可以工作,但所有其他路由都被重定向到相同的host gator 404 页面

我们将不胜感激您的 cmets 和答案。

谢谢

【问题讨论】:

  • 抱歉,你想让你的 laravel 项目在 http://gator4057.temp.domains/~timely/email-client/ 上运行,对吗?
  • @HenryBui 是的,这就是我要找的东西
  • 我认为不能,因为当你去http://gator4057.temp.domains/~timely/email-client/public时,主机可以理解必须去~timely/email-client/public。但是当你去http://gator4057.temp.domains/~timely/email-client/xxx时,你的主人不明白。你试过http://gator4057.temp.domains/~timely/email-client/public/xxx
  • 也不行
  • 这个目录下有 laravel 代码吗? MyUser/public_html/[laravel 代码在这里]?我的意思是在 public_html 内的服务器上

标签: php laravel .htaccess mod-rewrite


【解决方案1】:

第 1 步。 将所有 email-client/public 移动到 email-client/。现在我们正在取得进展。警告:不要忘记复制 .htaccess 文件

第 2 步。在您喜欢的编辑器中打开 email-client/index.php 并更改

$app = require __DIR__.'/../bootstrap/app.php';

$app = require __DIR__.'/../email-client/bootstrap/app.php';
or may be
$app = require __DIR__.'/email-client/bootstrap/app.php';

并改变:

require __DIR__.'/../bootstrap/autoload.php'

require __DIR__.'/../laravel/bootstrap/autoload.php'
or may be
require __DIR__.'/laravel/bootstrap/autoload.php'

运行命令:

php artisan cache:clear  
php artisan config:clear
php artisan optimize

如果你不想做更多的改变,试试这个:

把这个放在 index.php 文件中

$app->bind('path.public', function() {
    return __DIR__;
}

希望对你有用。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-08-03
  • 2011-03-22
  • 1970-01-01
  • 2011-11-15
  • 2013-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多