网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 代码交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

代码交流 ASP,PHP,JSP等网站源代码下载与交流。

Reply
 
Thread Tools Display Modes
  #1   IP: 112.84.222.250
Old 2014-01-02, 03:49 PM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default .htaccess实现www 与没有www之间的重定向

建站过程中有时候我们需要做这些设置 1.访问www 直接重定向到没有www上或者反过来,那么怎么通过.htaccess文件来实现呢。

1.首先服务器要支持Rewrite重写

2.创建.htaccess文件 当然如果你不知道个文件是做什么的你可以查看http://httpd.apache.org/docs/1.3/howto/htaccess.html

那我们开始吧,在文件的顶部我们要写如下代码:




01.RewriteEngine On
02.Options +FollowSymLinks



1. 如果你想将所有没有www的页面重定向到有www的上面你们复制下面的代码到.htaccess文件中

Then if you want to redirect all non-www requests to www copy the following code in .htaccess

Code:
# 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

Code:
# Redirect www to non-www   
RewriteCond %{HTTP_HOST} ^www\.(.*)   
RewriteRule (.*) http://%1/$1 [R=301,L]
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 09:19 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.