【发布时间】:2017-11-22 07:02:46
【问题描述】:
我正在尝试建立一个测试站点,但在让.htaccess 正确重定向时遇到了问题。
我希望在用户键入 test.example.com 时显示 www.example.com/test 的内容。我的重写规则允许我在地址栏中使用test.example.com,但它实际上显示的是根目录 (www.example.com) 的内容,而不是 test 子文件夹。
无论如何,我都不是.htaccess 大师,但我已经使用 Stack Overflow 5 年了,这是我第一次被难住而无法提出问题!感谢您的集体智慧。
这是我的.htaccess 代码的相关部分:
RewriteEngine On
# Rewrite for http cases
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
# Rewrite for no www cases
RewriteCond %{HTTP_HOST} !www\.example\.com [NC]
#redirect for test subdomain
RewriteCond %{HTTP_HOST} !^test\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# redirect to correct for old subfolder usage
RewriteRule ^oldsubfolder/$ https://www.example.com/ [L,R=301]
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite subdomain