1

I've wordpress project in (html_public) folder, and my domain run project fine, I want integrate laravel8 project inside the wordpress, so that both run in the same domain like That:

WordPress URLs:

  • https://example.com/wordpressHomepage

  • https://example.com/AnotherwordpressPage

Laravel URLs:

  • https://example.com/public/LaravelPage

  • https://example.com/public/LaravelPage/Id

Wordpress && LaravelApp path in cpanel:

public_html/
wp-admin
wp-content/
wp-includes/
... other wordpress files ...
laravelApp/ <-- laravel application folder
|-> app/
|-> bootstrap/
|-> config/
|-> public/
|-> ... other laravel files and directories ...

Wordpress .haccess:

# 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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Laravel .haccess in /public:

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

wordpress index.php:

    <?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';

Laravel index.php in App/public/index.php:

    <?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

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

/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
    require $maintenance;
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

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

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

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

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()
)->send();

$kernel->terminate($request, $response);

please any help?

4
  • What have you tried? What is your existing config? The “default” config should already handle something like this, so what is the actual problem you are having? (Aside: do you really want the word “public” in your URLs?) Commented Feb 23, 2022 at 11:09
  • Thanks for reply, the existing config is the default for laravel and wordpress, yes i want "public" in URL path to distinguishing between laravel and wordpress URLS Commented Feb 23, 2022 at 11:59
  • Please add your current configuration to your question, ie. the contents of both the WP and Laravel .htaccess files and where these reside. As I say, there should be very little (if anything) you would need to change to achieve the config you are after. Commented Feb 23, 2022 at 12:29
  • I updated question with configuration Commented Feb 23, 2022 at 12:55

2 Answers 2

1

Create one folder in the root directory and dump your laravel project folder in that and create .htaccess inside laravel project folder then point that .htaccess to the laravel public directory index file. your project will run smoothly. But my suggestion is to go with VPS hosting which will have you root access.

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Thanks for reply but could u explain more how .haccess configuration will be?
1
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

Assuming your Laravel .htaccess file is inside the /public subdirectory then simply remove (or comment out) the first two rules.

For example:

#RewriteCond %{REQUEST_FILENAME} -d [OR]
#RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule ^ ^$1 [N]

#RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
#RewriteRule ^(.*)$ public/$1
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

This does assume that server.php is also located inside the /public subdirectory.

3 Comments

Sorry for that, the .haccess was in root of laravelApp not in public subdirectory, I updated it now could you review it?
Just to add... this does assume that server.php is also located inside the /public subdirectory. @MahmoudDiab
server.php not located in /public, it is in root path of laravel app should i move it to /public ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.