Wordpress 302 通过 htaccess 临时重定向

Wordpress 302 Temporary redirect via htaccess

我需要暂时移动我的站点目录,以便我可以在域根目录中放入登录页面。着陆页将位于子域中并指向根域(通过 DNS)。

我正在尝试通过 htaccess 进行简单的 302 重定向,以从 https://example.com/ to https://example.com/home/ 更改网站目录,但我陷入了循环。 当我加载网站时,我永远得到这个...

https://example.com/home/home/home/home/home/home/

有什么想法可以让它发挥作用吗?

Redirect 302 / https://example.com/home/


# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

mod_aliasRedirect指令是前缀匹配,匹配后的所有内容都被复制到目标URL的末尾。因此,相同的指令会将 /home/(匹配 /)重定向到 /home/home/home/ 附加在目标上),等等

由于您已经在 WordPress 代码块中使用了 mod_rewrite,因此您也应该在此处使用 mod_rewrite 以避免潜在的冲突。 mod_rewrite 总是在 mod_alias 之前执行,与 .htaccess.

中指令的顺序无关

例如,要 302 重定向根,然后使用以下代替:

RewriteRule ^$ /home/ [R,L]

显然,当您在根目录中实施备用着陆页时,需要删除此重定向。

The landing page will live at a subdomain and point to the root domain (via DNS).

但是,如果您通过“子域”(如评论中所建议的那样)实施此“着陆页”,那么我不确定您为什么需要移动现有的主页,因为它存在于不同的主机名上。 (?)

但是在子域(大概指向主域文档根目录)上实施新的登录页面将创建一个非常脱节的站点。子域和主域是两个不同的站点。

如果您想在 WordPress 之外(在同一域中)创建一个新的登录页面(替换旧主页),那么我看不出如何实现从旧主页到 /home/ 因为这会自然地重定向新的着陆页 - 除非这只是您所说的“临时”,直到实施新的着陆页?

据我所知,您需要:

  1. 使用主页的现有内容为 /home/ 创建一个新的 WP 页面。 (现有的 WP 主页将无法再访问。)

  2. 在单独的子目录(在 URL 中不可见)中创建新的登录页面 - 或者可能只是一个单独的文件(例如 /new-landing-page.php)如果这是一个比较简单的页面。

  3. 在内部重写从文档根目录(否则会显示 WP 主页)到新登陆页面的请求,并防止请求通过 WordPress 路由。

    例如:

    # Rewrite requests for the homepage to the new landing page.
    RewriteRule ^$ new-site/new-landing-page.php [L]
    

    example.com/ 被请求时 example.com/new-site/new-landing-page.php 被提供(无重定向)。 WP 被绕过。但是 /<something> 是通过 WP 以通常的方式路由的。