本文介绍了使用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/pageandexample.co.uk/page -> www.example.co.uk/pageetc.

潜在的,可能会有几十个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(但与一捻)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:40
查看更多