开发者

Domain Forward .htaccess

How can I forward short-dom.com to long-domain.com ?

I keep seeing examples like:

RewriteCond %{HTTP_HO开发者_运维知识库ST} ^a\.com$ [NC]
RewriteRule ^(.*)$ http://www.a.com/$1 [L,R=301]

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

But these don't allow me to specify my short domain (all combinations of it - with or without www.)...


In the examples in your question, the place you specify the domain is on the line that says RewriteCond.

For example, this condition

RewriteCond %{HTTP_HOST} ^old\.example\.com$ [NC]

will match if the host name in the http request (%{HTTP_HOST}) matches the regular expression that follows. Your examples will match "a.com" while mine will match "old.example.com".

The line that says RewriteRule will do the actual rewriting. In your example it will replace

http://a.com/anything

with

http://www.a.com/anything

by substituting the regular expression matched with a new URL.

^(.*)$ matches the entire request and $1 substitutes it in the new URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜