.htaccess 在wordpress网站的子文件夹中安装laravel应用程序

qkf9rpyu  于 2022-11-16  发布在  WordPress
关注(0)|答案(1)|浏览(148)

我正在尝试在WordPress网站的子文件夹中安装Laravel应用程序。
这个想法是,当请求转到example.com/{anything}时,WordPress网站将作出响应,但如果请求是在example.com/get-started/* 上发出的,则Laravel网站将处理该请求。
我在网上找到了一些类似的问题,但没有一个对我有效。最近我试过的是this one from laracasts
我的根htaccess文件是

# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/get-started [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

我的htaccess从'get-started'文件夹是

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

“get-started/public”文件夹中的htaccess是

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

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

当我打开example. com/get-started时,它显示了laravel的默认404页面,告诉我重定向正在工作,但laravel应用程序没有相应的路由。
我把我的web.php文件给你

Route::redirect('/', '/step/1')->name('home');

Route::match(['GET', 'POST'], '/1', [\App\Http\Controllers\HomeController::class, 'step1'])->name('1');
Route::match(['GET', 'POST'], '/2', [\App\Http\Controllers\HomeController::class, 'step2'])->name('2');
Route::match(['GET', 'POST'], '/3', [\App\Http\Controllers\HomeController::class, 'step3'])->name('3');

我使用的是Laravel的this preset

x6yk4ghg

x6yk4ghg1#

我还没有设置这一点,但我认为2个选项。
1.在Laravel config中将公用文件夹的路径更改为/get-started/
1.就像wordpress在子目录中安装时捕获路径一样,您应该在相关RewriteCond(s)之前的get-started/public中向您的.htaccess中添加某个位置:

RewriteBase /get-started/

希望能成功。

相关问题