【问题标题】:Can Domain and Subdomain have same URL pattern on same server(.htaccess)?域和子域可以在同一服务器(.htaccess)上具有相同的 URL 模式吗?
【发布时间】:2014-10-13 18:58:15
【问题描述】:

我正在使用“m”子域为现有网站创建移动网站。 我被 htaccess 规则困住了。我对 htaccess 非常陌生,并且对正则表达式非常不利。

网站名称 - xyz.com

子域 - m.xyz.com

我希望每当我的网页被重定向(或直接在其中打开)到移动设备时,子域应该 具有与主域完全相同的 URL,但应转到移动版本文件,即

播放器

domain - xyz.com/5  -- real url - xyz.com/account.php?ln=5 (this account.php is in root folder)
Subdomain - m.xyz.com/5 -- real url - m.xyz.com/account.php?ln=5 (this account.php is in subfolder m)

团队

domain - xyz.com/TeamName/10  -- real url - xyz.com/team.php?ln=10 (this team.php is in root folder)
Subdomain - m.xyz.com/TeamName/10 -- real url - m.xyz.com/team.php?ln=10 (this team.php is in subfolder m)

游戏

domain - xyz.com/GameName/18  -- real url - xyz.com/game.php?p=18&t=game (this game.php is in root folder)
Subdomain - m.xyz.com/GameName/18 -- real url - m.xyz.com/game.php?p=18&t=game (this game.php is in subfolder m)

xyz.com 适用于所有组合,但是当我点击子域时,它并没有指向正确的文件。

当我尝试点击 m.xyz.com/TeamName/10 时,它会重定向到 http://m.xyz.com/m/game.php/?p=45&t=TeamName,但应该已经去了 m.xyz.com/team.php?ln=5(到子文件夹 m 中的文件)。直接 URL 有效。

目录结构:

xyz(htdocs)
 |
 --- account.php
 |
 --- team.php
 |
 --- game.php
 |
 --- m (Subdirectory - Subdomain)
     |
     --- account.php
     |
     --- team.php
     |
     --- game.php

.htaccess 文件 -

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

  #Add trailing slash to url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !([a-zA-Z0-9]\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ $1/ [R=301,L]

  #Remove .php-extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^([^\.]+)/$ $1.php

  #player 1 Parameter = Account Id
  RewriteRule ^([0-9]+)\/?$ account.php?ln=$1 [NC]

  #team 2 parameter = team name + team ID
  RewriteRule ^([a-z0-9_-]+)\/([0-9]+)\/?$ team.php?ln=$2 [NC]

  #game page = game ID + game Name + type
  RewriteRule ^([a-z0-9_-]+)\/([a-z0-9_-]+)\/([0-9]+)\/?$ game.php?p=$3&t=$2 [NC]


# End of Apache Rewrite Rules
</IfModule>

如果你有任何答案,请看看,让我知道,在谷歌上搜索了近三天已经没有运气了。

【问题讨论】:

    标签: regex .htaccess dns subdomain


    【解决方案1】:

    啊,钉它..这是一个非常简单的捕获.. dint意识到我在我的子域文件夹(root/m)中缺少.htaccess。在子域中复制了相同的 htaccess,它就像魅力一样。简而言之,对于可能试图找到答案的其他人来说......

    域和子域都需要一个 .htaccess 文件,如果您尝试为移动站点创建一个精确的域复制站点,则您的子域目录中必须有同名的文件,您只需将 htaccess 文件的副本放在您用于域的子域。

    意识到这很容易......愚蠢的我......(这就是你学习的方式:D)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 2015-02-07
      • 2020-03-23
      • 1970-01-01
      • 2015-08-13
      相关资源
      最近更新 更多