我有一个example.com,我在Cpanel中为它创建了一个子域 . 在Cpanel中出现:
test.domain.com /public_html/test not redirected 我想访问我的新子域:test.domain.com我在子域文件夹中创建了一个index.html:/ home / domainname / public_html / test
我的.htaccess是:
AddType text/x-component .htc
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RedirectMatch 301 ^/test/(.*)$ http://test.example.com/$1
RewriteRule ^(en|fr)/([a-z]*) /index.php
RewriteRule !\.
(js|ico|gif|jpg|jpeg|png|css|swf|htm|xml|php|map|ttf|woff|woff2)$
index.php
RewriteRule ^(form|ajax|captcha)/([a-z]*) /index.php
domain.com有ssl和subdomain我不喜欢 . 我在.htaccess中为子域添加了这一行:
RedirectMatch 301 ^/test/(.*)$ http://test.example.com/$1
但不工作:访问test.example.com时,我得到 "This page isn’t working test.example.com redirected you too many times."
如果与https一起使用:
RedirectMatch 301 ^/test/(.*)$ https://test.example.com/$1
我当然得到一个ssl警告和 Not Found The requested URL /home/domainname/public_html/index.php was not found on this server.
我做错了什么?
1 回答
你应该添加RewriteBase指令:
您还应该将RedirectMatch指令更新为:
它测试请求域是否为
example.com
,如果请求URI前缀为test/{any_characters}
,则永久重定向到test.example.com/{any_characters}
.