apache .htaccess 子域重写规则
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/366586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess Rewrite Rules for subdomain
提问by Simon B. Jensen
I use codeigniter as my main install on the main domain. I have created a subdomain and a folder called live e.g. live.domain.com maps to public/live . However in public I use codeigniter.
我使用 codeigniter 作为我在主域上的主要安装。我创建了一个子域和一个名为 live 的文件夹,例如 live.domain.com 映射到 public/live 。但是在公共场合我使用 codeigniter。
I now have the dynamic codeigniter url:
我现在有了动态 codeigniter 网址:
http://domain.com/api/
which I want to map to my subdomain:
我想映射到我的子域:
https://live.domain.com
So going to:
所以要去:
https://live.domain.com/api/functioname
would be using the script:
将使用脚本:
http://domain.com/api/apifunctioname
and possibly:
并且可能:
http://domain.com/api/apifunctioname/parameter1/parameter
Everything is on the same server so no redirects are needed.
一切都在同一台服务器上,因此不需要重定向。
Anyone have any ideas on which rewrite rules to use?
任何人对使用哪些重写规则有任何想法?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com [NC]
RewriteRule (.+)$ "http://domain.com/api/" [L]
The above works great as a rewrite but redirects to http://domain.com/api/functionnameinstead I want it to route; so that when going to:
以上作为重写效果很好,但重定向到http://domain.com/api/functionname而我希望它路由;所以当去:
https://live.domain.com/api/functioname
It stays at that url but uses the script of
它停留在那个网址,但使用的脚本
http://domain.com/api/functionname
Thank you very much,
非常感谢,
Ice
冰
回答by Simon B. Jensen
How about something like the following:
怎么样像下面这样:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/api/" [L,P]
回答by Muhammad Hamizi Jaminan
Just add index.php, see below
只需添加index.php,见下文
RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/index.php/api/" [L,P]

