htaccess的重定向子域域 [英] htaccess redirect subdomain to domain

查看:394
本文介绍了htaccess的重定向子域域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多与此相关的主题帖。但找到一个完全一样将花费大量的时间。所以生病只是简单地问agian如果已经问过。

我想这样的somename.mysite.com一个URL重定向到像mysite.com/test/somename的URL。注意somename是一个daynamic价值,我怎么能写的htaccess的rewrite_rule?

在htaccess的文件已经有一些:

 < IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
重写规则^指数\ .PHP $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
< / IfModule>
 

在哪里我把你给我的答案。

感谢您事先的任何帮助。

解决方案

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上
    的RewriteBase /

    的RewriteCond%{HTTP_HOST} ^(\ W +)\。mysite的\ .COM [NC]
    重写规则。* http://mysite.com/test/%1 [R,L]

    重写规则^指数\ .PHP $  -  [L]
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    重写规则。的index.php [L]
< / IfModule>
 

there are a lot of posts related to this topic. but finding one exactly the same will take a lot of time. so Ill just simply ask agian if this has been asked before.

I would like to redirect a url like this "somename.mysite.com" to a url like "mysite.com/test/somename". notice the "somename" is a daynamic value, how can I write the rewrite_rule in htaccess?

in htaccess file there is already something:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

where do I place the answer you give me.

Thank you for any help in advance.

解决方案

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} ^(\w+)\.mysite\.com [NC]
    RewriteRule .* http://mysite.com/test/%1 [R,L]

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

这篇关于htaccess的重定向子域域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆