wordpress - .htaccess 中的 301 重定向错误?WP网站
问题描述
我website.com
在自己的子域上重新制作了 Wordpress 上的旧网站remake.mydomain.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 的菜鸟,可能应该使用重定向条件和规则,但尽管我在谷歌上搜索,但我无法掌握这些概念,也没有找到任何简单的解释来说明这一切作品。
解决方案
如果我理解正确,您想从旧域重定向到 website.com,如果是这种情况,则将以下内容添加到您的 .htaccess 文件的最顶部并保持其余规则不变。
请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine ON
##Redirect from remake.mydomain.com TO website.com here.
RewriteCond %{HTTP_HOST} remake\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://website.com%{REQUEST_URI} [R=301,NE,L]
##Redirecting from website.com/en TO website.com
RewriteRule ^en/?$ / [NC,R=301,L]
##Redirecting from website.com/en/wheel-alignment-2 TO website.com/service/wheel-alignment
RewriteRule ^en/wheel-alignment-2/?$ service/wheel-alignment [NC,R=301,L]
##Redirecting from website.com/en/news--sales TO website.com/news-and-sales
RewriteRule ^en/news--sales/?$ news-and-sales [NC,R=301,L]
推荐阅读
- python - TypeError:不支持的操作数类型 -:LSTM 中的“float”和“tuple”问题
- android - Android:将带有可播放视频的意图发送到电报应用程序
- r - 替换列中的 -99
- android - 为什么这不能检索 Firebase 存储上图像的下载 URL?
- javascript - 如何获取页面上除div之外的所有元素
- grammar - 有没有办法消除这些减少/减少冲突?
- android - Recyclerview 仅显示 1 项
- webassembly - 如何从 binutils 构建 `gas`/`as` 到 wasm(并支持所有目标)?
- powershell - 有没有办法从 PowerShell 中的数字签名中获取一个人的姓名/电子邮件?
- pine-script - 是否有解决方案将系列转换为 pine 编辑器中的单个数据?