我正在使用" 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中的文件)。直接网址有效。
目录结构:
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>
如果您有任何答案,请查看并告诉我,在Google上搜索了近三天已经没有运气了。
答案 0 :(得分:0)
Ahh Nailed it ..这是一个非常简单的捕获.. dint意识到我错过了我的子域文件夹(root / m)中的.htaccess。在子域中复制相同的htaccess,它就像魅力一样。用其他可能试图找到答案的人的简单的话来说......
域和子域都需要.htaccess文件,如果您尝试为移动站点创建精确的域复制站点,则必须在子域目录中具有相同名称的文件,您只需要放置htaccess文件的副本您用于域名的子域名。
Dint意识到这很容易......愚蠢的我......(这就是你学习的方法:D)