简体   繁体   中英

Wordpress htaccess not working with subdirectory

i have directory offering-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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM