重写URL以非WWW多个站点 [英] rewrite url to non www multiple sites

查看:79
本文介绍了重写URL以非WWW多个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它们使用相同的文件,但不同的模板运行的一些网站,我的目标是强制使用的所有的www和非www域名。

i have some sites they are running with the same files but different templates, my goal is to force use all www or non www domains.

这是我的code:

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{HTTP:Host} ^[^.]+\.[a-z]{2,5}$ [NC]
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

把它从另一个问题上的计算器:)

get it from other question on stackoverflow :)

但是,如果我用WWW域名一切正常,如果没有得到这个重定向

But if I use www domain all is ok, if not get this redirect

http://domain.de/www/htdocs/user/_production/http%28?s%29://www。

推荐答案

为什么不简化像这样的规则:

Why not simplify your rules like this:

Options +FollowSymLinks -MultiViews
RewriteEngine on

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

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

这篇关于重写URL以非WWW多个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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