如何使用WordPress多站点重定向特定网站上的主页

发布于 2025-02-04 02:51:21 字数 1596 浏览 2 评论 0原文

我有一个WordPress网站,并安装了多站点。 WordPress是根(例如example.com/)。我的其他网站(多站点)就像portfolio.example.com

我不希望我的主页成为我的WordPress网站。我希望它是我创建的主页(使用我的CSS和JS),并且在example.com/index的文件夹中。

我尝试用重定向301/index.php https://example.com/index重定向301 https://example.com https://example.com/索引,但它将所有我的index.php重定向到example.com/index,甚至portfolio.example.com > example.com/index 由于WordPress结构。

如何将我的主页重定向example.com example.com/index 保留portfolio.example.com to portfolio。 example.com

我希望这很清楚...谢谢!

这是我的.htaccess(这是WP +我的重定向线生成的):

# BEGIN WordPress
# Les directives (lignes) entre « BEGIN WordPress » et « END WordPress » sont générées
# dynamiquement, et doivent être modifiées uniquement via les filtres WordPress.
# Toute modification des directives situées entre ces marqueurs sera surchargée.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]


# Redirection d’une URL vers une autre
Redirect 301 /index.php https://mysite.au/index


</IfModule>

# END WordPress

I have a WordPress site and I installed Multisite. WordPress is at the root (like example.com/). My other sites (multisite) are like portfolio.example.com.

I don't want my home page to be my WordPress site. I want it to be the home page I created (with my CSS and my JS) and it is in a folder in example.com/index.

I tried to redirect with a Redirect 301 /index.php https://example.com/index and a Redirect 301 https://example.com https://example.com/index but it redirects all my index.php to example.com/index so even portfolio.example.com becomes example.com/index because of the WordPress structure.

How can I redirect only my home page example.com to example.com/index keeping portfolio.example.com to portfolio.example.com?

I hope this is clear... Thanks!

Here is my .htaccess (it's the one generated by WP + my redirection line) :

# BEGIN WordPress
# Les directives (lignes) entre « BEGIN WordPress » et « END WordPress » sont générées
# dynamiquement, et doivent être modifiées uniquement via les filtres WordPress.
# Toute modification des directives situées entre ces marqueurs sera surchargée.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]


# Redirection d’une URL vers une autre
Redirect 301 /index.php https://mysite.au/index


</IfModule>

# END WordPress

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

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

发布评论

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

评论(1

┊风居住的梦幻卍 2025-02-11 02:51:21

您不能简单地重定向/重写index.php,因为那是WordPress前控制器,所有请求都写入其中。

我希望您想在内部“重写”请求,而不是外部“重定向”该请求,并将用户保持在“主页” URL,即。 example.com/,而不是公开/index/index.html的真实位置。

您可以将mod_rewrite用于内部重写(不是“重定向”)直接请求(而不是重写的请求),该请求将文档root to /index/index.html

请注意,您不应在#开始wordpress#end wordpress注释标记之间手动编辑代码,因为WordPress本身会维护此代码块,并将尝试覆盖以后的代码。

.htaccess文件的最顶部尝试以下内容, #开始WordPress注释标记。

# Rewrite the "example.com" homepage to "/index/index.html"
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php)?$ index/index.html [END]

# BEGIN WordPress
:

条件redirect_status环境变量进行检查,可确保仅重写用户的直接请求,而不会由后来的WordPress重写内部重写。

但是,以上允许用户请求//index.php/index/index.html访问您的自定义主页(即。

如果直接要求,您应该在之前包括一个“重定向” 此删除index.php(或index/index.html)。然后可以简化上述重写。例如,请尝试以下内容:

# Redirect to remove "index.php" or "index/index.html" if requested directly
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php|index/index\.html)$ / [R=301,L]

# Rewrite the homepage to "/index/index.html"
RewriteCond %{HTTP_HOST} ^example\.com [NC]   
RewriteRule ^$ index/index.html [END]

# BEGIN WordPress
:

You can't simply redirect/rewrite index.php since that is the WordPress front-controller and all requests are written to it.

I would have expected you to want to internally "rewrite" the request, rather than externally "redirect" the request, and keep the user at the "homepage" URL, ie. example.com/, rather than expose the true location of /index/index.html.

You can use mod_rewrite to internally rewrite (not "redirect") direct requests (as opposed to rewritten requests) for the document root to /index/index.html.

Note that you should not manually edit the code between the # BEGIN WordPress and # END WordPress comment markers since WordPress itself maintains this block of code and will try to overwrite this later.

Try the following to the very top of the .htaccess file, before the # BEGIN WordPress comment marker.

# Rewrite the "example.com" homepage to "/index/index.html"
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php)?$ index/index.html [END]

# BEGIN WordPress
:

The condition that checks against the REDIRECT_STATUS environment variable ensures that only direct requests from the user are rewritten and not internally rewritten requests by the later WordPress rewrite.

However, the above allows the user to request /, /index.php or /index/index.html to access your custom homepage (ie. /index/index.html).

You should include a "redirect" before this that removes index.php (or index/index.html) if requested directly. The above rewrite can then be simplified. For example, try the following instead:

# Redirect to remove "index.php" or "index/index.html" if requested directly
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php|index/index\.html)$ / [R=301,L]

# Rewrite the homepage to "/index/index.html"
RewriteCond %{HTTP_HOST} ^example\.com [NC]   
RewriteRule ^$ index/index.html [END]

# BEGIN WordPress
:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文