htaccess的重写,包括WWW,包括URL的休息 [英] rewrite htaccess to include www and include rest of url

查看:122
本文介绍了htaccess的重写,包括WWW,包括URL的休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面code reditrects用户WWW,如果WWW是在url中失踪,但你怎么redrirect相同的URL仅仅包括WWW

The following code reditrects the user to www, if the www is missing in the url, however how do you redrirect to the same url just including www

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

例如上面的重定向:

Eg the above redirects:

mydomain.com/goHere /

mydomain.com/goHere/

www.mydomain.com

www.mydomain.com

但我想它重定向到

www.mydomain.com/goHere /

www.mydomain.com/goHere/

在此先感谢任何反应。 Ĵ

Thanks in advance to any responders. J

推荐答案

试试这个code:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}  [R=301,L]

请一定要测试这在不同的浏览器或清除浏览器缓存。

Make sure to test this in a different browser or clear your browser cache.

这篇关于htaccess的重写,包括WWW,包括URL的休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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