开发者

HTACCESS: *.subdomain.domain.tld redir to subdomain.domain.tld/*

sorry for the vague question title.

But anyways,

I have here a subdomain which i wish to pass on wildcard sub-subdomains and make a proper htaccess redirect to a sub-folder (relative to the server root) equivalent to the wildcard value such that

*.subdomain.domain.tld will redirect to 开发者_如何学Gosubdomain.domain.tld/*

where * = wildcard value

I hope you get my question. Can someone shed some light on this? I would appreciate it very much =)


RewriteRule ^(.*).subdomain.domain.tld$ http://subdomain.domain.tld/$1 [R]
That should do the trick.

The [R] tells the server that this is a redirect. You can also use optional codes, say

[R=301] # Moved permanently
[R=302] # Moved temporarily
[R=403] # Forbidden
[R=404] # Not Found
[R=410] # Gone


You have to read the subdomain's name with RewriteCond and then you can do the Redirect with RewriteRule, while the subdomain is saved in %1.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.subdomain\.domain\.tld$ [NC]
RewriteRule .* http://subdomain.domain.tld/%1 [L,R=301]

If you want to redirect *.subdomain.domain.tld/file.html to subdomain.domain.tld/*/file.html, you can replace the RewriteRule with this:

RewriteRule ^(.*)$ http://subdomain.domain.tld/%1/$1 [L,R=301]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜