How to install wordpress in laravel public folder - wordpress

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

Related

Wordpress on a subdirectory of Laravel - Wordpress pretty permalinks inner page shows laravel

I read lots of discussions about this and found no solution. I have a Laravel web app and added a Wordpress blog (Blog) in a subdirectory public. This is what my .htaccess looks like within the public folder:
<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]
And this is my .htaccess in wordpress root directory
<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>
If I use the plain permalinks, everything works fine. If I use any other type of permalink it adds index.php to the URL and shows me the Laravel app. The permalinks adds the index.php in the permalinks page:
look here, currently all this is well but if i use any type of permalinks no(plain) it's not work
The funny thing is, if I choose the post name permalink with the %postname% in it, the URL is:
http://localhost:8000/blog/postname/
and I see the laravel app, but the same URL with the admin
(http://localhost:8000/blog/wp-admin/) or any other admin pages, works fine.
I really don't want to have to use ugly permalinks here.
Is there a solution?
NB - as you can see on the url, the site is currently on localhost using APACHE in kali linux
The conditions in the Laravel rewrite are probably matching. Requests to WordPress won't match a file or directory and will be rewritten by the rule:
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try adding a condition to not rewrite for the blog directory:
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^ index.php [L]

Wordpress redirect issue from clean wp install to subdirectory

I have a problem with a wordpress site as follows:
A website was built on http://example-domain.com.
I have build a wordpress site on http://example-domain.com/wordpress.
I want to delete everything in public.html folder and put a clean wordpress there.
The problem is that after I installed the clean wordpress, I keep getting redirected to the /wordpress subdirectory.
What I have tried:
Changed the site URL and home from example http://example-domain.com/wordpress to http://example-domain.com, copied a clean htaccess file in the new wp instalation.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Before, I had 2 htaccess files, one just like the one mentioned above, that was located in the subdirectory and one in the root like this:
DirectoryIndex /wordpress/index.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
Extra info: It is not a cache or cookie nor browser issue.
Update:
I was watching the Network tab in dev tools on Chrome and saw this error.
Any help would be greatly appreciated!
Did you changed the existing database urls from http://example-domain.com/wordpress to http://example-domain.com ?
Export the existing database, open in a text editor, do find-replace for the url's(from subdirectory to root directory) as mentioned above. Then import it into the new database. Once done, a fresh htaccess like this in the public/html root folder should be working fine.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

How can I transfer a wordpress project from one server into another server sub-directory?

I have an installed worpress project which is working on server_A. To transfer it, I created a zip file of all files that are in the public_html of serevr_A. and uploaded it in the server_B/mag/.
Also I've exported/imported the database in the new server and modified new credentials in the wp-config.php. Noted that, the database connection works well in the new server.
The problem is, when I open the project on the new server http://example.com/mag through the browser, it says:
Page not found
I guess it's because of that sub-directory in the new server named mag (because the installed wordpress project been on the root of the old server).
Anyway, do you know how can I make it working?
The content of .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
I use Laravel framework and this is the content of the main (root) .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
In .htacess you need to do following change add your folder name in rewrite base and rule. Below will work for you.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mag/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mag/index.php [L]
</IfModule>
# END WordPress
Sometimes you need to change the websites url in your wordpress database via the wp_options table.
You'll see two fields ralating to those shown in the WP admin settings, edit these accordingly.

wordpress permalink and https and folder redirect

I "inherited" a website at the department I am working at that is hosted on a machine we don't have root access to. I managed to force https with the .htaccess file, but I was unable to add wordpress permalinks to it also. The combinations I tried all ended up pointing every link to the front page.
This is the .htaccess we have now (the wordpress website is in a subdirectory):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^familydogproject.elte.hu$
RewriteCond %{REQUEST_URI} !wordpress/
RewriteRule ^ https://%{HTTP_HOST}/wordpress/%{REQUEST_URI} [L,R=301]
And this is the example wordpress gave for the permalinks:
# 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
Does anybody have any idea how to combine them?

Redirect Rule in htaccess for a folder

I have a wordpress hosting site www.mysite.com/myBlog . The wordpress installation is done inside public_html/www/myBlog folder inside my host folder.
I also have a folder public_html/www/myName which redirects me to a domain myName.com
Although this works fine but inside myName folder i have files like index.html. acad.html, worexp.html
clicking on them i expect a behavior like
myName.com/index.html
myName.com/acad.html
myName.com/workex.html
though i get it as myname.com only.
I found htaccess rules in myName folder as :
Redirect http://mydomainName.com/myName/+
# 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
RewriteCond %{HTTP_HOST} ^mydomainName.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomainName\.com\/myBlog" [R=301,L]
Can anyone help me with whats wrong with the htaccess file ?
More details:
My WordPress blog has something messed up. I can go to my blog and homepage works fine but when i try to go to any post it throws an 403 error. Apache forbidden.
Tried talking to web host for permissions its ok.
checked htaccess. Replaced code by default code stil not working.
Removed permalinks to default deleted htaccess created new permalinks.
Gave permissions to all the files in blog directory
Rewrote robots.txt Blog url is : www.windowsvj.com
Wordpress community is not able to suggest something very helpful too.
Current Redirect rule code in .htaccess is :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L]
</IfModule>
# END WordPress
This could be the result of FollowSymLinks being disabled in the server configuration. Simply adding Options +FollowSymlinks to the .htaccess file could do the trick.
Instead of using the flag [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L] <---
</IfModule>
# END WordPress
Try using [QSA]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [QSA] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [QSA] <---
</IfModule>
# END WordPress
How [L] works is if the RewriteRule matches
RewriteRule . /wpblog/index.php [L]
Then all other rewrites after this RewriteRule are ignored as stated on the Apache website
"In most contexts, this means that if the rule matches, no further rules will be processed." http://httpd.apache.org/docs/current/rewrite/flags.html
Here is a link with more information on .htaccess flags
http://httpd.apache.org/docs/current/rewrite/flags.html
Hope this works for you :P

Resources