【问题标题】:subdomain to act as a parameter in .htaccess and php not working子域作为 .htaccess 中的参数,而 php 不起作用
【发布时间】:2020-10-17 16:13:39
【问题描述】:

我知道这个话题已经在这个论坛上讨论过很多次了,但是我完全迷失了 .htaccess 并且非常感谢任何关于这个查询的帮助

我在一个网站上有 2 个子域

aaa.sitename.com bbb.sitename.com

子域没有子文件夹,所有查询都进入站点的默认文件夹

我的意图是将 2 个值传递给 index.php,如下所示

aaa.sitename.com/clubvalue ==> index.php?md=aaa&club=clubvalue

bbb.sitename.com/clubvalue ==> index.php?md=bbb&club=8868

它们在如下调用时工作正常(我可以使用 $_GET 提取 md 和俱乐部详细信息)

www.sitename.com/index.php?md=aaa&club=2323

aaa.sitename.com/index.php?md=aaa&club=2323

bbb.sitename.com/index.php?md=bbb&club=2323

但是当被称为

aaa.sitename.com/2323

它显示 404 页面未找到错误

如果被称为 aaa.sitename.com

md 和 club 都返回一个空值

我的.htaccess文件如下..

RewriteEngine On
RewriteBase /

#Also do not rewrite real files
RewriteCond %{REQUEST_FILENAME} !-f

#For everything else, index.php should fetch the proper content
RewriteCond %{HTTP_HOST} ^([a-z]{1,2})\.domain\.xx$ [NC]
RewriteRule ^([^/]+)/?$ index.php?club=%1&md=$2 [QSA,L]

谢谢

【问题讨论】:

  • 您的 RewriteCond 要求子域部分仅包含一个或两个字母。根据您给出的示例,这可能是这里的问题吗?

标签: php apache .htaccess subdomain


【解决方案1】:

我会发送任何东西到 index.php 页面并在那里分解 GET 变量。

如果您有 WordPress 的副本,则使用它的 .htaccess 或下载 WordPress 并使用它的 .htaccess。

【讨论】:

    猜你喜欢
    • 2012-03-22
    • 2018-08-07
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多