如何执行从 index.htm 到 root 的简单 301 重定向?

发布于 2024-08-25 14:20:54 字数 503 浏览 3 评论 0 原文

我读过各种有关重定向的参考网站,说实话我了解甚少。

目前,我的 .htaccess 中有标准的 WordPress mod_rewrite 重定向规则:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

我的相当多的引荐来源网址都转到旧 URL http://www.example.com/index.htm,这会给他们带来错误,我希望它们能够无缝重定向到 http://www.example.com/。我相信 301 重定向是最好的方法。

我需要做什么?

I've read various reference sites on redirection, and to be honest I understand very little.

I currently have standard WordPress mod_rewrite redirect rules in my .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Quite a few of my referrers go to a old URL http://www.example.com/index.htm, which gives them an error, and I want them to be seamlessly redirected to http://www.example.com/. I believe a 301 redirect is the best method for this.

What do I need to do?

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

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

发布评论

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

评论(3

熊抱啵儿 2024-09-01 14:20:54
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

这会将所有出现的index.html 或index.htm 递归地转换为目录。

RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

This will translate all occurrences of index.html or index.htm to just the directory, recursively.

薄暮涼年 2024-09-01 14:20:54

我不是 100% 确定,但我想应该是 RewriteRule ^index.htm$ / [R=301] 或类似的东西

I'm not 100% sure but i guess that should be RewriteRule ^index.htm$ / [R=301] or something like this

抚你发端 2024-09-01 14:20:54

创建一个index.html,包含以下代码:

<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=the-other-url">
</HEAD>
<BODY>
You will be redirected...
</BODY>
</HTML> 

其中“秒”是重定向之前的延迟持续时间(以秒为单位)。设置“0”以进行即时重定向。

“the-other-url”是 http://www.example.com/index.php

Create an index.html, containing the code:

<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=the-other-url">
</HEAD>
<BODY>
You will be redirected...
</BODY>
</HTML> 

Where "seconds" is the duration of the delay (in seconds) before the redirection. Set a "0" for instant redirect.

"the-other-url" is http://www.example.com/index.php

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