apache - .htaccess 子域的重写规则

标签 apache .htaccess mod-rewrite url-rewriting

我使用 codeigniter 作为我在主域上的主要安装。我创建了一个子域和一个名为 live 的文件夹,例如live.domain.com 映射到 public/live 。但是在公共(public)场合我使用codeigniter。

我现在有动态 codeigniter url:

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/$1" [L]

上面的代码非常适合重写,但重定向到 http://domain.com/api/functionname相反,我希望它路由;这样当去:

https://live.domain.com/api/functioname

它停留在该网址,但使用的脚本

http://domain.com/api/functionname

非常感谢你,

最佳答案

像下面这样的东西怎么样:

重写引擎开启
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/api/$1"[L,P]

关于apache - .htaccess 子域的重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/366586/

相关文章:

regex - 使用 mod_rewrite 更改永久链接现在会出现内部服务器错误 500

wordpress - 让 .htaccess 阻止子域,除非来自其他某些子域(对于 wp-admin 安全 WordPress)

php - 服务器签名关闭在 .htaccess 上不起作用

java - SSL 连接重置

apache - 如何在 apache2 中禁用 mod_deflate?

apache - 如何从文件中动态读取updateAttribute 中属性的值?

apache - 允许访问 Apache 服务器上隐藏目录中的文件(尤其是 ".well-known"文件夹)

php - http_response_code() 总是返回 200,即使是 404

apache - apache https 重定向错误(不受信任的连接)

apache - mod_rewrite : rewrite urls to point to the same application