如何修改.htaccess文件始终重定向到www [英] how to modify .htaccess file to always redirect to www

查看:261
本文介绍了如何修改.htaccess文件始终重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改我的.htaccess文件,这样当有人进入我的网站,而无需输入WWW网站总是他们重定向到www的版本。例如,如果我的网址是www.abc.com,他们只需要输入abc.com,我想将它们重​​定向到abc.com。

I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my url is www.abc.com and they just type abc.com, I want to redirect them to abc.com.

下面是我目前的htaccess文件:

Here is my current htaccess file:

<IfModule mod_rewrite.c>
   RewriteBase /
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]  
</IfModule>

通常情况下,我知道该怎么做了重定向,但有问题的,因为它已经拥有那几行中有IM。

Normally I know how to do the redirect, but im having issues since it already has those few lines in there.

推荐答案

后,立即 RewriteEngine叙述添加像这样的

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]

这篇关于如何修改.htaccess文件始终重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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