Install wordpress alongside in laravel in apache server - wordpress

I have put my wordpress in public/blog folder in laravel. In my case after putting this RewriteCond $1 !^(blog) into .htaccess file I can install and access wordpress through www.mysite.com/blog. The only problem is when I change permalinks from this /blog/?p=123 to this /blog/%postname%/. It gives me error in laravel
NotFoundHttpException in RouteCollection.php line 161
so how can I have post with nice path like www.mysite.com/blog/my-post?

Just setting RewriteCond $1 !^(blog) is not enough.
Replace the line with RewriteCond %{REQUEST_URI} !^/blog/, so it'll ignore all URIs that start with /blog/.
Then don't forget to change the WP .htaccess too:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ #change here
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] #change here
</IfModule>

Related

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 returns 404 on existing file

I have the following stucture:
Wordpress installed in root, and an /api/api.php file manually created
When I go to www.example.com/api/api.php I get a 404
This is my .htaccess in the root folder:
Options +FollowSymLinks
RewriteRule ^api/api\.php$ - [L]
# 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 expect this should have let requests to /api/api.php through unmolested.
Also, I tried putting in a .htaccess file in /api with just
# disable the rewrite engine
RewriteEngine off
but I am still getting a 404 error despite this.
The rest of the site works fine, and I have tried disabling all WP plugins just in case.
try change your permalink from admin panel or if you have an IIS7 server then your permalink should be like %postname%index.php.
and also try this .htaccess code and instead of 'example' write your site base path name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]

Wordpress mod_rewrite exception for a subdirectory

I am using GoDaddy Delux Hosting, Linux server. I have a wordpress installation in the root directory. I've started a development directory under the root directory. I don't have a wordpress installation under the development directory, but my own project.
My objective is to circumvent wordpress url rewriting just for the development directory, and redirect every url that starts with the development directory to development/index.php. I have experimented with numerous mod_rewrite combinations, but I couldn't get it work. I get the standard wordpress "page not found" page for everything except mysite.com/development/index.php
The last configuration I've come up with is the following:
root directory .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(development|development/.*)$
RewriteRule . /index.php [L]
</IfModule>
development directory .htaccess file:
RewriteEngine On
RewriteRule .* index.php [L]
Any ideas how to best approach this?
PS: I haven't used "development" in Wordpress as a slug.
In the main .htaccess file you should ignore anything under "development" - you don't need the initial forward slash because of RewriteBase / and you can make the trailing slash optional with a ?, and there is no need for .*$.
In the subdirectory you ignore anything not in the subdirectory for rewrites using RewriteBase /development/ sending everything to /development/index.php where the request is not a file or directory.
Give the following a try:
/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^development/?
RewriteRule . /index.php [L]
</IfModule>
/development/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /development/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /development/index.php [L]
</IfModule>

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