htaccess,将虚拟子域重定向到 URL 参数 [英] htaccess, redirect virtual subdomain to URL parameter
问题描述
我有一个 .ne.ro 域(在罗马尼亚注册),访问者可以在其中输入或不输入www":
http://mydomain.ne.ro
http://www.mydomain.ne.ro
我想将 http://123.mydomain.ne.ro
重定向到 http://mydomain.ne.ro?id=123
.如果访问者输入'www|mail|ftp' 必须被视为非参数(显然).
我尝试了 到相关问题.
I have a .ne.ro domain (registered in Romania) where visitors can enter with or without 'www':
http://mydomain.ne.ro
http://www.mydomain.ne.ro
I want to redirect http://123.mydomain.ne.ro
to http://mydomain.ne.ro?id=123
. If visitor enter with 'www|mail|ftp' must be treated as non parameter (obviously).
I tried htaccess subdomain redirct with last url parameter but didn't work.
Current code:
# edited on 05/April/2011 as suggested:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mydomain.ne.ro$
RewriteCond %{HTTP_HOST} ^(.*).mydomain.ne.ro$
RewriteRule ^$ /index.php?id=%1 [R,L]
Hosted on a hostgator's business plan (linux) and registered at nic.ro, just if asking.
After many suggested code (thanks supersuphot) and a lot of research finally I found an answer.
First I added the subdomain * under mydomain.ne.ro, pointed to domain folder/path:
Then I uploaded .htaccess file with the next code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mydomain.ne.ro
RewriteCond %{HTTP_HOST} ^(.+).mydomain.ne.ro
RewriteRule ^([^/]*)$ http://mydomain.ne.ro/?id=%1 [P,L]
this works too:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mydomain.ne.ro$
RewriteCond %{HTTP_HOST} ^(.*).mydomain.ne.ro$
RewriteRule ^$ /index.php?id=%1 [P,L]
The most important thing is the P instead R at last line, to keep original subdomain. Check this answer to a related question.
这篇关于htaccess,将虚拟子域重定向到 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!