WordPress页面php片段以获取所有请求到子目录

发布于 2025-02-11 02:09:34 字数 391 浏览 2 评论 0原文

我正在为WordPress网站页面开发PHP片段。想象一下,此片段位于位于一个页面上,

wp-example.com/abc

但是当我致电

wp-example.com/abc/def

WordPress时,假设它是完全不同的页面,并且说页面不存在,并且我的片段不应用。

在我的php片段中,位于wp-example.com/abc上,如何将所有请求获取到SubDirectories example> example> example.com/abc/**

编辑:我不想修改我的Web服务器配置,我想纯粹在WordPress中执行此操作

I am developing a PHP snippet for a Wordpress website page. Imagine this snippet is at a page located at

wp-example.com/abc

But when I call

wp-example.com/abc/def

Wordpress assumes it is a totally different page and says page does not exist, and my snippet is not applied.

In my PHP snippet, located at wp-example.com/abc, how can I fetch all the requests to subdirectories example.com/abc/**?

edit: I don't want to amend my web server configuration, I want to do that purely within Wordpress

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何处潇湘 2025-02-18 02:09:34

您可以通过添加到.htaccess文件2行来解决此问题:(未测试)

RewriteEngine on
RewriteRule ^/?abc/(.*)$ /abc [R,L]

You can solve this by addding to .htaccess file 2 lines: (not tested)

RewriteEngine on
RewriteRule ^/?abc/(.*)$ /abc [R,L]
小梨窩很甜 2025-02-18 02:09:34

使用此.htaccess代码。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]
</IfModule>

Use this .htaccess code.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]
</IfModule>
傻比既视感 2025-02-18 02:09:34

步骤1:允许多站点

启用网络设置菜单项,您必须首先在 wp-config.php 文件中定义多站点。

打开wp-config.php并在上面添加此行 ,它说这就是停止编辑! Happy Bloging .. 如果在任何地方都没有说,请添加以要求开头的第一行以上的某个地方或包括:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

步骤2:安装网络

上一步启用启用网络设置您的工具菜单中的项目。使用该菜单项,转到创建WordPress站点网络屏幕。

要查看创建WordPress网站网络屏幕网络的示例,请查看管理&gt; tools&gt;网络设置。在所有情况下,屏幕看起来都不完全相同。显示的示例是用于Localhost上的安装,该安装限制了可用的选项。

https://prnt.sc/28zphhke7zuq

您的网络,按照创建WordPress站点屏幕网络上的说明。您看到的说明是为安装定制的。它们可能与您在此处看到的示例不同。

https://prnt.sc/xbgn0dubwmjr 直接上方
该片段看起来像这样,但是适应您自己的网站:

// Example code but it is not the code of your website
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'My Website');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

将第二个代码段添加到 .htaccess 文件中并替换其他WordPress规则。

// Example code but it is not the code of your website key
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Step 1: Allow Multisite

To enable the Network Setup menu item, you must first define multisite in the wp-config.php file.

Open up wp-config.php and add this line above where it says That's all, stop editing! Happy blogging.. If it doesn’t say that anywhere, then add the line somewhere above the first line that begins with require or include:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

Step 2: Installing a Network

The previous step enables the Network Setup item in your Tools menu. Use that menu item to go to the Create a Network of WordPress Sites screen.

To see an example of the Create a Network of WordPress Sites screen, look at Administration >Tools > Network Setup. The screen does not look exactly the same in all circumstances. The example shown is for an installation on localhost, which restricts the options available.
https://prnt.sc/28ZPHhke7ZuQ

Step 3: Enabling the Network

To enable your network, follow the instructions on the Create a Network of WordPress Sites screen. The instructions that you see are customized for your installation. They might not be the same as the examples you see here.
https://prnt.sc/XBGn0dUbWMJR

Add the first code snippet to your wp-config.php directly above the line
The snippet looks like this, but adapted to your own site:

// Example code but it is not the code of your website
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'My Website');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Add the second code snippet to the .htaccess file and replace other WordPress rules.

// Example code but it is not the code of your website key
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文