【问题标题】:Laravel alongside WordPress on a shared hostLaravel 与 WordPress 在共享主机上
【发布时间】:2020-03-11 15:23:25
【问题描述】:

我在共享主机上有一个 wordpress 网站,我想为它创建一个 laravel 管理面板。
我基于 this page 工作过,我的文件结构是这样的:

domains/
│
└── mydomain.com/
    │
    ├── laravel/
    │    │
    │    └── laravel files
    │
    └── public_html/
          │
          ├── wordpress files
          │
          └── appadmin/
              │
              ├── css/
              │
              ├── fonts/
              │
              ├── js/
              .
              .
              .
              │
              ├── .htaccess
              │
              └── index.php

并更改了appadmin/index.php 以访问laravel 文件。
index.php:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));


require __DIR__.'/../../laravel/vendor/autoload.php';

$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
//...

我的 laravel 管理员登录路径是 /login,这意味着 laravel 管理员登录 url 是 mydomain.com/appadmin/login 并且工作正常。

但是!当我输入用户名和密码(不管是错还是正确)并点击提交按钮时,页面将重定向到mydomain.com/wp-login.php

编辑:这些是 laravel 和 wp .htaccess 文件

wp h​​taccess:

# BEGIN iThemes Security - این خط را تغییر یا حذف نکنید
# iThemes Security Config Details: 2
    # مسدودسازی میزبان - امنیت > تنظیمات > کاربران مسدود شده
    SetEnvIF REMOTE_ADDR "^5\.45\.69\.4$" DenyAccess
    SetEnvIF X-FORWARDED-FOR "^5\.45\.69\.4$" DenyAccess
    SetEnvIF X-CLUSTER-CLIENT-IP "^5\.45\.69\.4$" DenyAccess

    SetEnvIF REMOTE_ADDR "^192\.99\.15\.141$" DenyAccess
    SetEnvIF X-FORWARDED-FOR "^192\.99\.15\.141$" DenyAccess
    SetEnvIF X-CLUSTER-CLIENT-IP "^192\.99\.15\.141$" DenyAccess

    SetEnvIF REMOTE_ADDR "^149\.56\.241\.211$" DenyAccess
    SetEnvIF X-FORWARDED-FOR "^149\.56\.241\.211$" DenyAccess
    SetEnvIF X-CLUSTER-CLIENT-IP "^149\.56\.241\.211$" DenyAccess

    SetEnvIF REMOTE_ADDR "^31\.222\.187\.197$" DenyAccess
    SetEnvIF X-FORWARDED-FOR "^31\.222\.187\.197$" DenyAccess
    SetEnvIF X-CLUSTER-CLIENT-IP "^31\.222\.187\.197$" DenyAccess

    <IfModule mod_litespeed.c>
        Order allow,deny
        Allow from all
        Deny from env=DenyAccess
        Deny from 5.45.69.4
        Deny from 192.99.15.141
        Deny from 149.56.241.211
        Deny from 31.222.187.197
    </IfModule>
# END iThemes Security - این خط را تغییر یا حذف نکنید

# This file was updated by Duplicator on 2018-12-05 08:05:28. See .htaccess.orig for the original .htaccess file.
# Please note that other plugins and resources write to this file. If the time-stamp above is different
# than the current time-stamp on the file system then another resource has updated this file.
# Duplicator only writes to this file once during the install process while running the installer.php file.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(appadmin|user)($|/) - [L] #To Shailor's suggestion
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

laravelhtaccess:

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

    RewriteEngine On

    # 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>

【问题讨论】:

  • 我是否理解正确,您可以看到 Laravel 登录页面但无法提交?
  • @Johannes 是的!成功登录后,它应该重定向到/appadmin/dashboard,但无论如何它都会重定向到/wp-login.php
  • 您说您按照上述指南进行操作,但是为什么要回到这里的两个目录级别? $app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
  • @Johannes 基于我项目的文件夹结构,laravel filesappadmin files 之间相对于指南有一个额外的级别

标签: php wordpress laravel shared-hosting laravel-6


【解决方案1】:

重新检查 laravel 和 wordpress .htaccess 文件。 要排除 appadmin,您应该在任何其他 RewriteRule 之前将此行添加到 wp 的 .htaccess。如果这不能解决您的问题,请使用 .htaccess 文件更新您的问题,我也会更新我的答案

RewriteRule ^(appadmin|user)($|/) - [L]

【讨论】:

  • 问题与RewriteBase /有关。 WordPress `.htaccess` 位于您域的根文件夹中,因此会将所有请求重定向到 wordpress 安装。尝试在 Shalior 的回复中省略 |user,并确保规则位于 Rewrite Base / 下方的一行。
猜你喜欢
  • 1970-01-01
  • 2019-01-28
  • 2017-07-07
  • 2018-06-21
  • 2020-01-16
  • 1970-01-01
  • 2013-07-05
  • 2018-03-15
  • 1970-01-01
相关资源
最近更新 更多