Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

Wordpress permalinks problem installed in laravel with apache

I have a laravel application in: domain.com/co/app that controls it routes/web.php with code Route::post('/co/app'... I have installed wordpress in the public folder of laravel (laravel/public/co) resulting in the blog: domain.com/co.

But when I activate the permalinks in wordpress the lavarel application (domain.com/co/app) I get a wordpress 404 error.

I have ignored the path of the application from the wordpress .htaccess RewriteCond %{REQUEST_URI} !(app) [NC] but now I get an apache 404 error (The requested URL was not found on this server) and it does not show the laravel application.

This is the code of the .htaccess wordpress (laravel/public/co):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /co/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /co/index.php [L]
</IfModule>

This is the code of the .htaccesss de public (laravel/public)

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

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

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

This is the Route code of the Laravel application (laravel/routes/web.php)

Route::post('/co/app', [
'uses' => 'App@aaa'
])->name('app');

Thanks for the help

question from:https://stackoverflow.com/questions/65650173/wordpress-permalinks-problem-installed-in-laravel-with-apache

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the answer, in this special case, first you do not have to edit anything in the .htaccesss of laravel/public you only have to edit the wordpress (laravel/public/co). Ignoring the laravel application path with RewriteCond %{REQUEST_URI} !^/co/app and adding a new module that points to the index.php of laravel/public

The problem is that WordPress can intentionally edit your .htaccess and delete our modification, for that we use a hack that is explained here.

My final wordpress .htaccess code is:

<IfModule mod_ignore_wordpress.c>
# 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 /co/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /co/index.php [L]
</IfModule>
# END WordPress
</IfModule>

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /co/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_URI} !^/co/app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /co/index.php [L]
</IfModule>
#new module
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /co/app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...