首页 文章

为子域配置.htaccess

提问于
浏览
0

我有一个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 回答

  • 3

    你应该添加RewriteBase指令:

    RewriteEngine on
    RewriteBase /
    

    您还应该将RedirectMatch指令更新为:

    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule ^test/(.*)$ http://test.example.com/$1 [R=301,L]
    

    它测试请求域是否为 example.com ,如果请求URI前缀为 test/{any_characters} ,则永久重定向到 test.example.com/{any_characters} .

相关问题