Problems to rewrite URL with Laravel, Wordpress and Apache - wordpress

I have a question / problem with a Laravel project and Wordpress
My Laravel project is multilanguage and the URL is:https://example.com/en/ (look at the /en/)
This project use a blog in Wordpress with this URL https://example.com/en/news
If the directory /en/ exists physically, Apache reads the directory before the friendly path of my project (https://example.com/en is the homepage). The error code is 403, empty directory obviusly.
I tried to move the WordPress installation to another folder like /wordpress/ and rewrite the path of that folder using htaccess but it doesn't work.
I don't know if it's because this doesn't work, or because what I'm trying is impossible
This is the htaccess of the public folder with the Laravel project. I'm using a Plesk server with Apache + Nginx
<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]

Related

Apache access to example.com/app from different root directory

For now, I have following directories:
WordPress directory is connected with example.com domain. I would like to access my Zend app by example.com/app URL, but it is in separated directory. I tried to add rewrite rule in htaccess file in WordPress directory, but server responds me with 400 error. I tried that without success:
RewriteRule ^app/(.*)$ ../zend_app/$1
And now I am not sure what to do. I think about some php file to include something from zend_app folder or to create symlink inside WordPress directory pointing to zend_app folder. What solution is better? Maybe there is another solution? I am using shared hosting, so possibilities are limited.
EDIT:
Here is my whole htaccess file from WordPress:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^app/(.*)$ zend_app/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Laravel pointing subfolder into other name

I have a laravel project that include multiple domain inside.
I want to make the blog for each domain using wordpress. I already install the wordpress succesfully, but since this laravel project is a multiple domain inside, I install the wordpress project for each domain using "domainname_blog" on the public folder.
public_html
|- public
|- aa_blog
|- bb_blog
|- cc_blog
What I want to ask is, is it possible to access the blog using aa.com/blog instead of aa.com/aa_blog?
I hope I can access aa.com/blog that pointing to aa_blog without any redirecting, because now I only can access it using aa.com/aa_blog. I tried a lot of changing htaccess method but still not working.
Please for your advice.
Thanks
You need to segregate the Blog Folder from your laravel .htaccess file. Please write the code into your .htaccess file [ laravel ]. Hope it will solve your issue.
RewriteCond $1 !^(blog)
.htaccess file will look like :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond $1 !^(blog)
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
# 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]

How to install wordpress in laravel public folder

i also follow this link but this is not my solution - laravel and wordpress on the same domain(laravel in subfolder)
i want to add wordpress in my laravel site.
so i install all wordpress in my laravel's public folders. here i create one folder "blog" and in this folder i install my wordpress site.
but my problem is when i run my wordpress site like that localhost:8000/blog it work fine
But when i am try to oprn another link then laravel redirect me 404 page not found.
so how to run wordpress in laravel if make any changes in any file so please any one help me.
my laravel public folder's .htaccess look like that
<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}]
To run wordpress as subdirectory, you must change the .htaccess file inside worpress directory like below:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Follow this guide for more information
https://wordpress.org/support/article/giving-wordpress-its-own-directory/
Well that quite simple if you have a laravel application such as laravel.
What you have to do is just:
download wordpress form wordpress.org
rename that downloaded wordpress folder to any name such as blog
put that blog folder into a public directory of laravel
put database credential of wordpress blog into wp-config.php
as well as put laravel db credential in .env
make change in .htaccess of laravel
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} http://localhost/laravel/public/$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} http://localhost/laravel/public/$
RewriteRule ^(/)?$ blog/index.php [L]
</IfModule>
You can easily access your blog as
http://localhost/laravel/public/blog
It will start wordpress blog

.htaccess, WordPress and mod_speling

I've got a server that has in its root directory a bunch of subdirectories, one of which has a WordPress.
directory1
directory2
wordpress
directory3
All of these except for the WordPress were migrated from a Windows server to a Linux server which means that we've lost case insensitivity.
I want the WordPress to be able to serve a URL like http://www.example.com/~subdomain, so there's an index file in the root directory. I also have two .htaccess files, one in the WordPress and one in the root directory.
The following is the root directory's .htaccess.
This is where I'd like to put mod_speling's case insensitivity directives, but it conflicts with the rewrite rule.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~subdomain/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~subdomain/index.php [L]
</IfModule>
# END WordPress
Below is the WordPress subdirectory's .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~subdomain/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~subdomain/wordpress/index.php [L]
</IfModule>
# END WordPress
I've tried using a symlink in the root directory to point to the WordPress directory's index.php. I set the symlink to be the DirectoryIndex but unfortunately it results in a lot of the links turning into 404s.
At this point I'm kind of stuck. Any ideas?

WordPress in root folder and vBulletin in subfolder

I installed WordPress in my host root folder and I installed vBulletin in a subfolder.
I changed my WordPress default permalink to "postname".
Now when I want to open forum (the vBulletin subfolder), it redirects to root folder (WordPress) and gives "not found post".
When I delete .htaccess file in the root folder (WordPress), the subfolder works fine, but accessing WordPress posts gives 404 error.
How can I solve this problem?
It is my WordPress .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And this is the subfolder (vBulletin) .htaccess file:
# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine on
# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /
RewriteCond %{HTTP_HOST} !^soft-game\.ir
RewriteRule (.*) http://soft-game.ir/forums/$1 [L,R=301]
RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap|api\.php)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]
You should install wordpress and vBulletin in seperate folders, because a sub-folder in the wordpress insallation means that it is part of wordpress, and it will not act as an unique entity.
Create two folders, name first as 'blogs' or whatever for wordpress and create another folder in the root and name it 'forums' or whatever you like for vBulletin only then the 404 error from wordpress will disappear.

Resources