使用.htaccess将domain.co.uk/index.html重定向到www.domain.co.uk

发布于 2024-10-31 08:52:29 字数 1292 浏览 5 评论 0原文

我注意到搜索引擎一直在抓取我最近开发的网站的domain.co.uk 和www.domain.co.uk 版本。 使用 .htaccess 我已经能够设置 http 301 重定向,以便:

但是:

我的 .htaccess 的内容是(显然我已经替换了我的域名以简化问题):

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^domain.co.uk [nc]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,nc]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.co.uk/$1 [R=301,L]

我知道我可能遗漏了一些明显的东西,但请可以有人帮助我将最终重定向到 http://www.domain.co.uk 按预期工作吗?

I have noticed that search engines have been crawling both the domain.co.uk and www.domain.co.uk versions of a web site that I've recently developed.
Using .htaccess I have been able to setup http 301 redirects so that:

and

However:

The contents of my .htaccess are (obviously I have replaced my domain to simplify matters):

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^domain.co.uk [nc]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,nc]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.co.uk/$1 [R=301,L]

I know I am probably missing something obvious but please could someone help me get the final redirect to http://www.domain.co.uk working as expected?

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

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

发布评论

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

评论(1

冷血 2024-11-07 08:52:30

您的规则集的第一部分工作正常,缺少 www.已正确添加。对于第二部分,您只需要一个简单的规则来删除index.html,而不使用任何附加条件:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,NC]
RewriteRule ^index.html$ http://www.domain.co.uk/ [R=301,L]

我认为这应该可以解决问题。

The first part of your rule set is working fine, the missing www. is added correctly. For the second part you only need a simple rule to remove the index.html without using any additional condition:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,NC]
RewriteRule ^index.html$ http://www.domain.co.uk/ [R=301,L]

I think this should do the trick.

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