开发者

How do I rewrite url from subdomain to a link in the main domain?

I'm not very good in rewriting uris and was wondering whether someone could help me resolve this.

I am not looking for a redirect, but for a real url rewriting. I want to be able to enter:

contest.example.com

开发者_开发知识库and I want the server to load:

http://www.example.com/?page=contest

while in the address bar in the browser, there will be the original url, contest.example.com

I know I need to do this in .htaccess, I just don't know exactly how the rule will look.


Use this:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]+\index\.php.*(\?|&)page=
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}        !^www
RewriteCond %{HTTP_HOST}         ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^.*$ index.php?page=%1 [L,QSA]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜