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

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

问题描述

我想修改我的 .htaccess 文件,以便当有人在没有输入 www 的情况下进入我的网站时,该网站总是将他们重定向到 www 版本.例如,如果我的 url 是 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>

通常我知道如何进行重定向,但我遇到了问题,因为那里已经有几行了.

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

推荐答案

RewriteEngine on 之后立即添加类似的内容:

Add something like this immediately after RewriteEngine on:

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

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

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