php - .htaccess 将子域重定向到 ssl 站点

标签 php apache .htaccess redirect ssl

我想让我的网站http://subdomain.domain.com重定向到另一个外部 SSL 加密域 https://subdomain.external.com , 同时保留浏览栏中的原始地址。据我所知,使用 CNAME 可以很容易地做到这一点,但问题是它重定向到没有 SSL 加密的外部链接。

有人告诉我这可以通过 .htaccess 文件来完成,该文件现在具有以下内容:

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

你能帮我知道我应该如何修改 .htaccess 文件以满足我的要求吗?非常感谢!

胡安

最佳答案

如果你想用 PHP 来做:

$redirect = "https://www.ssl.com".$_SERVER['REQUEST_URI'];
header("Location: $redirect");
exit;

然后您必须通过 .htaccess 将所有请求路由到此 PHP 文件:

RewriteEngine on
RewriteRule ^([^.]+)$ index.php [QSA]

关于php - .htaccess 将子域重定向到 ssl 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056481/

相关文章:

php - Laravel4 中的路线 [RemindersController@postRemind] 未定义错误

php - SELECT 包含特定关键字 PHP 的所有行

mysql - 高流量下的 Varnish 高数据库连接

php 和 html 注册页面结果是空白页

PHP根据值拆分数组

php - MySQL启动错误-端口已被使用

php - 如何授予apache对所有文件的写权限

.htaccess - 阻止谷歌将我的页面索引为 ssl

php - 如何使用用户友好的 url (mod_rewrite) 处理网站上的原始 .php 文件

.htaccess - 我可以使用 DNS 或 .htaccess 将子域重定向到其他站点吗?