使用的.htaccess重定向domain.co.uk/index.html到www.domain.co.uk [英] Using .htaccess to redirect domain.co.uk/index.html to www.domain.co.uk

查看:125
本文介绍了使用的.htaccess重定向domain.co.uk/index.html到www.domain.co.uk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

不过:<​​/ P>

我的.htaccess中的内容(很明显,我已经取代我的域名,以简化事项):

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ domain.co.uk [NC]
重写规则^(。*)$ http://www.domain.co.uk/$1 [R = 301,NC]
的RewriteCond%{THE_REQUEST} ^ * / index.html的
重写规则^(。*)的index.html $ http://www.domain.co.uk/$1 [R = 301,L]
 

我知道我可能失去了一些东西明显,但请能有人帮助我得到最终重定向到 HTTP:// WWW .domain.co.uk 按预期工作?

解决方案

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

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ domain.co.uk [NC]
重写规则^(。*)$ http://www.domain.co.uk/$1 [R = 301,NC]
重写规则^ index.html的$ http://www.domain.co.uk/ [R = 301,L]
 

我想这应该做的伎俩。

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?

解决方案

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.

这篇关于使用的.htaccess重定向domain.co.uk/index.html到www.domain.co.uk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆