【发布时间】:2021-04-07 16:15:03
【问题描述】:
我已经在我自己的子域 remake.mydomain.com 上的 Wordpress 上重新制作了一个旧网站 website.com,现在我想将其移动到原始域 website.com,但我的大部分 URL 都已更改,所以我想重定向到新的,但其中一些没有按预期重定向(至少对我来说,因为我是 .htaccess 文件的菜鸟):
# 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
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 /en /
Redirect 301 /en/ /
# this works
...
Redirect 301 /en/wheel-alignment-2 /service/wheel-alignment/
Redirect 301 /en/wheel-alignment-2/ /service/wheel-alignment/
# redirects to /wheel-alignment-2 (page not found)
Redirect 301 /en/tire-mounting-2 /service/tire-mounting/
Redirect 301 /en/tire-mounting-2/ /service/tire-mounting/
# redirects to /tire-mounting-2 (page not found)
Redirect 301 /en/news--sales /news-and-sales/
Redirect 301 /en/news--sales/ /news-and-sales/
# redirects to /news--sales (page not found)
...
Redirect 301 /en/testimonials /
Redirect 301 /en/testimonials/ /
# this is the last redirect, redirects to /testimonials (page not found)
一个甚至重定向到 /wp-content/ 中的图像,但我发现 Yoast SEO 导致了这种情况,因此在“搜索外观”>“媒体”中关闭了“媒体和附件 URL”,它工作正常。
顺便说一句,如您所见,旧网站的 URL 中有语言扩展名,我不再需要它了。
最终结果应该是这样的:
website.com/en > website.com
website.com/en/wheel-alignment-2 > website.com/service/wheel-alignment
website.com/en/news--sales > website.com/news-and-sales
是否有人对我做错了什么以及如何正确执行此操作有任何建议?
正如我之前所说,我是一个 .htaccess 的菜鸟,可能应该使用重定向条件和规则,但尽管我用谷歌搜索,但我无法掌握这些概念,也没有找到任何简单的解释这一切是如何运作的。
【问题讨论】:
-
欢迎来到 SO 并感谢您在问题中分享您的 htaccess 文件。您能否也请提及您要重定向/重写的从哪个网址到哪个网址?为了更好地理解您的问题,请更新您的问题。
-
您好,谢谢您,网址不会改变,最终结果会保持不变,我只是在自己的域上创建了一个子域来创建新站点,然后我将迁移到原本的。我已经更新了我的问题,希望现在更清楚了。
标签: wordpress apache .htaccess redirect mod-rewrite