.htaccess实现www 与没有www之间的重定向
2012-03-15 10:15
330 查看
建站过程中有时候我们需要做这些设置 1.访问www 直接重定向到没有www上或者反过来,那么怎么通过.htaccess文件来实现呢。
1.首先服务器要支持Rewrite重写
2.创建.htaccess文件 当然如果你不知道个文件是做什么的你可以查看http://httpd.apache.org/docs/1.3/howto/htaccess.html
那我们开始吧,在文件的顶部我们要写如下代码:
1. 如果你想将所有没有www的页面重定向到有www的上面你们复制下面的代码到.htaccess文件中
Then if you want to redirect all non-www requests to www copy the following code in .htaccess
2. 如果你想将所有有www的页面重定向到没有www的上面你们复制下面的代码
If you want to redirect all www requests to non-www use the following
1.首先服务器要支持Rewrite重写
2.创建.htaccess文件 当然如果你不知道个文件是做什么的你可以查看http://httpd.apache.org/docs/1.3/howto/htaccess.html
那我们开始吧,在文件的顶部我们要写如下代码:
RewriteEngine On Options +FollowSymLinks
1. 如果你想将所有没有www的页面重定向到有www的上面你们复制下面的代码到.htaccess文件中
Then if you want to redirect all non-www requests to www copy the following code in .htaccess
# Redirect non-www to www RewriteCond %{HTTP_HOST} !^www\.(.*) RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
2. 如果你想将所有有www的页面重定向到没有www的上面你们复制下面的代码
If you want to redirect all www requests to non-www use the following
# Redirect www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*) RewriteRule (.*) http://%1/$1 [R=301,L]
相关文章推荐
- .htaccess实现www与没有www之间的重定向
- [转] .htaccess实现www 与没有www之间的重定向
- 使用async-http 重定向出错 & 文字没有焦点,仍实现自滚动
- scala BitSet实现算法:一千万个随机数,随机数范围在1到1亿之间,现在要求写出一种算法,将1到1亿之间没有出现的随机数求出来
- linux下apache开启.htaccess实现重定向
- Nginx 301 重定向实现不带www跳转到www
- 利用.htaccess 301实现子目录重定向或访问子目录重定向到二级域名
- inline-block text-align: justify 实现自适应布局, 当子inline-block之间没有空格时失效及原因
- cPanel修改.htaccess实现主域名重定向到子目录
- 如何实现301的跳转?当输入域名http://xxx.com的时候自动重定向到www上去
- .htaccess实现301网页永久重定向及302临时重定向
- scala BitSet实现算法:一千万个随机数,随机数范围在1到1亿之间,现在要求写出一种算法,将1到1亿之间没有出现的随机数求出来
- 在一个程序中需要用到全局变量(在多个class之间共享数据),请问如何定义具有这种功能的变量?或者是否有其他的方法解决多个class之间的数据共享(尽量简单实现)。 首先应该明确 Java中没有全局变
- iphone7中在块与块之间设置margin-bottom没有撑开,无法实现滚动效果
- 一起学Hadoop——实现两张表之间的连接操作
- android中Activity与service之间相互通信的实现方式
- .htaccess技巧: URL重写(Rewrite)与重定向(Redirect)
- Qt GraphicsView框架中实现多个item之间的层次调整功能
- Android开发实现HttpClient工具类(强,处理了很多你没有注意到的细节问题)
- 任意进制整数之间的相互转换(C++实现)