【发布时间】:2022-01-09 05:07:50
【问题描述】:
我正在将一个旧的 html 网站移动到 Wordpress。网站结构如下:
http://example.com/index.htmlhttp://example.com/about.htmlhttp://example.com/contact.html
在 WordPress 中它现在看起来像:
https://example.com/https://example.com/about/https://example.com/contact/
这是我的.htaccess 文件
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Redirect 301 /index.html https://example.com/
Redirect 301 /about.html https://example.com/about/
Redirect 301 /contact.html https://example.com/contact/
# BEGIN WordPress
<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
(在此处编辑以纠正我遇到的错误)
这有效,除了 http://example.com/index.html 301 重定向到 https://example.com/index.html,然后反复 301 重定向到 https://example.com/ 直到超时。
Redirect 301 /index.html https://example.com/ 无论我将它放在它所在的位置还是在 RewriteRule 行上方都会被忽略。
其他有效的重定向执行从 http://example.com/about.html 到 https://example.com/about.html 的 301 重定向,然后另一个 301 重定向到 https://example.com/about/ (200 OK)。
如何将http://example.com/index.html 重定向到https://example.com?
【问题讨论】:
-
你清除浏览器缓存了吗?
-
@AmitVerma - 我做到了,是的。
-
您是否建议正确重定向
http://example.com/about.html?只有/index.html有问题? -
@MrWhite - 没错。我也使用了重定向检查器进行测试。它显示 example.com/about.html 重定向 example.com/about.html 然后到 example.com/about 但 example.com/about.html 重定向到 example.com/about.html 并返回 404。
-
我假设您在第二个示例中是指
/index.html。下面的答案有帮助吗?
标签: wordpress .htaccess redirect mod-rewrite