使用htaccess的重定向非www的请求,WWW(但与一捻) [英] Using htaccess to redirect requests from non-www to www (but with a twist)

查看:123
本文介绍了使用htaccess的重定向非www的请求,WWW(但与一捻)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的htaccess强制所有请求使用WWW。所以:

I'm currently using htaccess to force all requests to use www. So:

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

重定向example.com/page到www.example.com/page。

to redirect example.com/page to www.example.com/page.

但是,此htaccess文件正在被example.com若干国际版本。什么code我想也可以做到以下几点:

However, this htaccess file is being used by several international versions of example.com. What code do I want that can also do the following:

example.de/page - > www.example.de/page 和 example.co.uk/page - > www.example.co.uk/page 等等。

example.de/page -> www.example.de/page and example.co.uk/page -> www.example.co.uk/page etc.

潜在的,可能会有几十个example.com的版本,所以我希望不必记住每次我们增加一个新的国家的时间来编辑htaccess的。

Potentially, there could be dozens of versions of example.com, so I'm looking to avoid having to remember to edit htaccess every time we add a new country.

推荐答案

您可以在您的字符串替换使用服务器变量,所以这应该是可行与

You can use server variables in your substition, so this should be doable with

RewriteRule ^(.*)$ http://www.${HTTP_HOST}/$1 [L,R=301]

这篇关于使用htaccess的重定向非www的请求,WWW(但与一捻)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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