使用.htaccess不起作用将旧站点重定向到新站点

发布于 2025-02-11 10:27:04 字数 1783 浏览 2 评论 0原文

我正在将我的网站URL从InvadingHolland.com更改为IncartallyDutch.com。我已经迁移了网站,现在将其放在两个位置。我正在尝试将旧站点上所有帖子和页面的重定向设置为新站点(使用旧站点的.htaccess文件)。重定向不起作用,但也没有打破。

插件中已经有一些重定向的代码(在两个地方),该插件将HTTP处理为我旧站点上的HTTPS重定向(几年前添加)。我想这是在某种程度上干涉,否则我将代码添加错误。如果有人能告诉我如何设置这个,我将非常感激。谢谢。

# BEGIN HTTPS Forced Redirect
# The directives (lines) between "BEGIN HTTPS Forced Redirect" and 
# "END HTTPS Forced Redirect" are dynamically generated, and should 
# only be modified via the filters. Any changes to the directives between 
# these markers will be overwritten.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>

# END HTTPS Forced Redirect

# Use PHP7.2 as default
# AddHandler application/x-httpd-ea-php72 .php
# BEGIN Really Simple SSL Redirect 5.3.0
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>
# END Really Simple SSL Redirect
# 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

I’m changing my site url from invadingholland.com to accidentallydutch.com. I’ve already migrated the site and now have it in the two locations. I’m trying to set up redirects from all posts and pages on the old site to the new one (using .htaccess file of the old site). The redirect is not working but nothing is breaking either.

There was some redirecting code already in there (in two places) for the plugin that handles the http to https redirects on my old site (added a few years ago). I guess that is interfering in some way or I’m adding my code in wrong. If anyone can tell me how to set this up I would be very grateful. Thanks.

# BEGIN HTTPS Forced Redirect
# The directives (lines) between "BEGIN HTTPS Forced Redirect" and 
# "END HTTPS Forced Redirect" are dynamically generated, and should 
# only be modified via the filters. Any changes to the directives between 
# these markers will be overwritten.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>

# END HTTPS Forced Redirect

# Use PHP7.2 as default
# AddHandler application/x-httpd-ea-php72 .php
# BEGIN Really Simple SSL Redirect 5.3.0
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>
# END Really Simple SSL Redirect
# 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

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

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

发布评论

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

评论(1

巷子口的你 2025-02-18 10:27:04
  repriteCond%{https} off
#rewriterule ^(。*)$ https://%{http_host}%{request_uri} [l,r = 301]
重写(。
 

您缺少参数之间的空间。 IE。 (。*)&lt; here&gt; https:// accid ...。最终结果是,以上是什么都不做的,因为正则是不匹配的。但是,您还保留了检查HTTPS状态(HTTP的一部分到HTTPS规则)的条件,因此仅将HTTP重定向(而不是HTTPS)。

假设新域指向另一个服务器,那么您在旧主机上不需要任何一个。删除现有.htaccess文件的内容,然后使用简单的mod_alias redirect指令:

# .htaccess at the old host/domain

# Redirect everything to the new domain
Redirect 301 / https://example.new/

redirect指令是前缀匹配和比赛后的所有内容被传递到目标。例如。 https://example.old/foo/bar被重定向到https://example.new/foo/bar

首先用302(临时)重定向测试,以避免潜在的缓存问题。


在新主机...

# BEGIN Really Simple SSL Redirect 5.3.0
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>
# END Really Simple SSL Redirect

您再次缺少&lt; space&gt;,如上所述。但是,本节由“非常简单的SSL”插件维护。无需更改它(您所做的任何更改都可能被插件覆盖)。

RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]

You are missing a space between arguments. ie. (.*)<here>https://accid.... The net result is that the above will do nothing because the regex never matches. However, you have also kept the condition that checks the HTTPS status (part of the HTTP to HTTPS rule), so this would only redirect HTTP (not HTTPS).

Assuming the new domain points to a different server then you don't need any of this at the old host. Delete the contents of the existing .htaccess file and use a simple mod_alias Redirect directive instead:

# .htaccess at the old host/domain

# Redirect everything to the new domain
Redirect 301 / https://example.new/

The Redirect directive is prefix matching and everything after the match is passed through to the target. eg. https://example.old/foo/bar is redirected to https://example.new/foo/bar.

Test first with a 302 (temporary) redirect to avoid potential caching issues.


At the new host...

# BEGIN Really Simple SSL Redirect 5.3.0
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule (.*)https://accidentallydutch.com/$1 [L,R=301]
</IfModule>
# END Really Simple SSL Redirect

You are missing a <space> again, as mentioned above. However, this section is maintained by the "Really Simple SSL" plugin. There's no real need to change it (and any changes you do make are likely to be overwritten by the plugin).

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