简体   繁体   English

Wordpress htaccess 不适用于子目录

[英]Wordpress htaccess not working with subdirectory

i have directory offering-pages in my domain我的域中有目录offering-pages

offering-pages/.htaccess code is提供页面/.htaccess 代码是

# 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.我访问 wordpress 的仪表板和我网站的主页。 when i go to other page like http://domain/offering-pages/offerings-for-students/ it display the content of domain/index.php当我转到其他页面时,如http://domain/offering-pages/offerings-for-students/它显示domain/index.php的内容

Try this script and change domain and subdomain according to their names and also post wordpress related question to wordpress.stackexchange 尝试使用此脚本并根据其名称更改域和子域,并将与wordpress相关的问题发布到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? 您是否在提供页面目录中安装了Wordpress? If so, you need to change index.php to point to your directory where Wordpress is installed. 如果是这样,则需要更改index.php以指向安装了Wordpress的目录。

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").顶级站点的自定义永久链接(“Plain”以外的任何内容)与子目录站点的自定义永久链接(“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).要修复(并且在修改或创建帖子和页面时不会得到“无效的 JSON 响应”),只需删除顶级站点的 .htaccess 文件(通常在 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.并且为了防止将来发生冲突,请转到顶部站点的站点设置 > WordPress 中的永久链接并将设置更改为普通,删除任何类别和标签库,然后单击保存。 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).当您单击 SAVE 时,将创建一个新的 .htaccess 文件或覆盖该目录的旧文件(而普通实际上意味着一个空的 .htaccess 文件或没有设置)。

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).这意味着您不会从顶级站点创建带有漂亮 URL 的页面和帖子(对于该特定站点,您必须使用自动生成的帖子或页面 URL,例如 example.com/?p=123 而不是 example .com/postname)。

Antonio Robateau安东尼奥·罗巴托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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