我如何使用mod_rewrite 301重定向example.com到www.example.com? [英] How can I use mod_rewrite to 301 redirect example.com to www.example.com?

查看:133
本文介绍了我如何使用mod_rewrite 301重定向example.com到www.example.com?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重定向的任何URL没有WWW。与URL的WWW。为更好的搜索引擎优化。我看,这是有可能的mod_rewrite及.htaccess文件,但我不知道正确的code使用。任何人都可以帮忙吗?

I need to redirect any URLs without "www." to URLs with "www." for better search engine optimization. I read that this is possible with mod_rewrite and .htaccess files, but I do not know the right code to use. Can anyone help?

推荐答案

在你的根文件夹中创建一个名为.htaccess文件(一个在那里,说,的index.html或index.php文件所在)。把下面进去:

Create a file called .htaccess in your root folder (the one where, say, index.html or index.php resides). Put the following into it:

RewriteEngine   on
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

这篇关于我如何使用mod_rewrite 301重定向example.com到www.example.com?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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