【问题标题】:Configure .htaccess for subdomain为子域配置 .htaccess
【发布时间】:2018-06-05 04:41:58
【问题描述】:

我有一个 example.com,我在 Cpanel 中为它创建了一个子域。在 Cpanel 中出现:

test.domain.com /public_html/test 未重定向 我想访问我的新子域: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,而子域我没有。我在 .htaccess 中为子域添加了这一行:

RedirectMatch 301 ^/test/(.*)$ http://test.example.com/$1

但不工作:访问 test.example.com 时,我得到 “此页面不工作 test.example.com 将您重定向了太多次。”

如果与 https 一起使用:

RedirectMatch 301 ^/test/(.*)$ https://test.example.com/$1

我当然会收到 ssl 警告和 未找到 在此服务器上找不到请求的 URL /home/domainname/public_html/index.php。

我做错了什么?

【问题讨论】:

  • 如果我评论 htaccess 它在子域中工作(它向我显示 html 页面)但域站点无法正常工作

标签: php .htaccess redirect cpanel


【解决方案1】:

你应该添加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}

【讨论】:

  • 嗨@Ben,如果理解正确,.htaccess 应该看起来像this。主域 example.com 正在运行,但子域 test.example.com 没有。我收到 ssl 警告(这不是问题,因为我会为此子域安装证书),然后:Not Found The requested URL /index.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
  • 您是否为您的子域设置了正确的DocumentRoot / 或正确的VirtualHost 配置?
  • 我没有修改任何配置。刚刚从 cpanel 创建了子域。错误 404 是因为它正在寻找 index.php 而不是 .html 现在它工作得几乎很好:) 我为该子域安装了 joombla,现在我必须处理另一个 .htaccess 文件来处理 test.example.com 的路由.非常感谢本 ;)
猜你喜欢
  • 2013-09-16
  • 1970-01-01
  • 1970-01-01
  • 2017-01-23
  • 2016-05-11
  • 1970-01-01
  • 2011-08-16
  • 1970-01-01
  • 2015-01-21
相关资源
最近更新 更多