【发布时间】: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