【发布时间】:2019-10-11 12:46:04
【问题描述】:
我想将https://example.com/sub/index.php 重定向到https://sub.example.com/index.php。
如您所知,子域网站空间位于实际的域网站空间中;这会导致内容重复。
我已经试过了:
-
在 index.php 的头部添加 javascript:
<script type='text/javascript'>document.location.href='https://example.com/sub/index.php';</script>但这会造成无限循环。
-
将 .htaccess 添加到 /sub/ 目录:
RewriteEngine On RewriteRule (.*) https://sub.example.com/index.php$1 [R=301,L]但这使得无法在 /sub/ 中创建其他文件,因为它总是将您重定向到 index.php
如果我还想在 /sub/ 中创建始终重定向到子域版本的其他文件,那么解决此问题的最佳方法是什么?
【问题讨论】:
-
子目录结构是否与子域相同? IE。
http://sub.example.com/path/to/my/file.php会重定向到http://example.com/sub/path/to/my/file.php吗? -
@bluemoon6790 应该是相反的,但是是的
标签: .htaccess redirect mod-rewrite