Wordpress htaccess not working with subdirectory - wordpress

i have directoryoffering-pages in my domain
offering-pages/.htaccess code is
# 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 access dashboard of wordpress and only the home page of my website.
when i go to other page like http://domain/offering-pages/offerings-for-students/ it display the content of domain/index.php

Try this script and change domain and subdomain according to their names and also post wordpress related question to wordpress.stackexchange
RewriteEngine On
# rewrite subdomains to separate folder
RewriteRule ^subdomain/ - [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^(.*)$ subdomain/$1 [L]
# or if you want to rewrite sub.domain.com/test to /subdomain/sub/test
#RewriteRule ^(.*)$ subdomain/%1/$1 [L]
# force www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
# END WordPress

Did you install Wordpress in the offering-pages directory? If so, you need to change index.php to point to your directory where Wordpress is installed.
From:
require(dirname(__FILE__) . '/wp-blog-header.php');
To:
require(dirname(__FILE__) . '/offering-pages/wp-blog-header.php');

SOLVED!!!
The top site's custom Permalinks (anything other than "Plain") clash with the subdirectory site's custom Permalinks (anything other than "Plain").
Both cannot be set to be custom (without a complicated solution).
To fix (and not get "Invalid JSON response" when modifying or creating Posts and Pages), simply delete the top site's .htaccess file (in the root directory usually under public_html).
And to prevent future clashes, go to the top site's site Settings > Permalinks in WordPress and change the setting to Plain, delete any Category and Tag Base, and click SAVE. When you click SAVE, a new .htaccess file is created or the old one is overwritten for that directory (and Plain actually means an empty .htaccess file or no setting).
This means that you won't be creating pages and posts with pretty URLs from the top site (for that specific site you'll have to use an auto-generated post or page url like example.com/?p=123 instead of example.com/postname).
Antonio Robateau

Related

How to use mod_rewrite without clashing with Wordpress

So I have Wordpress installed, let's call the domain test.com. The .htaccess that wordpress created in the default directory (the one that is one level above wp-content) is
# 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 want to add another rule, which if triggered, should case Wordpress to not rewrite. So for instance, suppose I want test.com/nochange to redirect to test.com/script.php, instead of doing the normal Wordpress redirects. Normally the .htaccess for this would be
RewriteRule ^nochange$ ./script.php [NC,L]
But what happens is that Wordpress ends up running anyways, and of course a 404 not found occurs. If I removed the Wordpress .htaccess components, everything works. What do I do to get them to work together?
Ah, I just needed to use the END tag.

Redirect all URLs to homepage except core WordPress files

I've recently gained access to a domain which used to have a very large site and product base, however the old host turned it off and all the URLs are lost. I am using WordPress on the domain (previously it used an e-com shop called Kyrptronic) and have set up a simple landing page. So far there are over 20,000 not found URLs and I need them to redirect to the homepage (except for css and jpg files that I am using on the landing page).
I tried to redirect all old links straight to homepage however this means the core wordpress files become inaccessable and when you try and click anything in the backend E.g. Plugins - it redirects to the homepage. Here is the code I used in the htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|xml)$
RewriteRule (.*) / [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Is there a htaccess code snippet that can redirect all URLs other than jpgs, pngs and NOT the entire wordpress and website directory with .php file extensions?
The site has too many not found URLs to do one by one.
Hope this makes sense, it's my first post on here!!
Thanks
You could try something like this (it must e above the wordpress routing rules):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|xml|php)$
RewriteRule ^ / [R=301,L]

Wordpress redirect to a subdirectory with permalinks

I have a wordpress blog in a subdirectory at domain.com/blog. I want to access it from the main domain, without anyone seeing it is in a subdirectory. I've managed to do a transparent redirect from the domain to the directory using some help, but I can't seem to get the pretty permalinks to work. This is what I use for the redirection:
RewriteEngine on
# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Only apply to URLs that aren't already under /blog.
RewriteCond %{REQUEST_URI} !^/blog/
# Rewrite all those to insert /blog.
RewriteRule ^(.*)$ /blog/$1
# Redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ blog/ [L]
And this is what I would use for permalinks if the blog wasn't in a subdirectory and there wouldn't be any redirects:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
As far as I've tried combining the two rulesets, I either get an infinite loop or a not found from wordpress.
So how can these two rulesets be merged, so that the blog could be accessed by redirecting to a subdirectory and friendly urls could be used?
Thanks
perma link is just a setting in your admin side
go to setting and look for that and change the website url
not the wordpress url!!

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.

Mask a forwarded url to wordpress in a directory

I built a website for a client at clientsite.com. She has a new business and wants a wordpress site. So I installed wordpress in clientsite.com/wordpress. I can't install wordpress in the root because that's where her original site is and I need the wordpress site in its own folder. She has a domain with godaddy called newbusiness.com. I assigned that to bluehost (her host provider) and added it as an addon and now when you go to newbusiness.com you see the pages located at clientsite.com/wordpress, and newbusiness.com in the address bar. Exactly what I want. EXCEPT, when you navigate to any other page on the site, the address bar changes back to clientsite.com/wordpress. Not good.
I'm having a HORRIBLE time trying to figure out how to keep newbusiness.com in the address bar throughout the whole site. Please help!
One really simple solution is to add a few lines to the .htaccess file in your /wordpress folder. This file is created during the installation, so it should be there. It probably contains the following:
# 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
Try adding these 3 lines:
RewriteCond %{HTTP_HOST} !newbusiness.com$ [NC]
RewriteCond %{REQUEST_URI} clientsite\.com/wordpress [NC]
RewriteRule ^(.*)clientsite\.com/wordpress(.*)$ $1newbusiness.com$2 [L,R=301]
right before </IfModule>

Resources