如何在htaccess中使用m.domain.com

时间:2016-12-22 10:15:44

标签: .htaccess subdomain

如何在浏览器栏中将 www.domain.com/mobile.html 显示为 m.domain.com

我的标准 index.html 文件位于根目录中,因此其地址为 www.domain.com/index.html

它使用javascript将用户重定向到 www.domain.com/mobile.html 的移动网站。

我只是希望它在地址栏中以不同方式显示,而不是更改mobile.html文件的实际位置。

1 个答案:

答案 0 :(得分:0)

我无法使用我的网络服务器上的.htaccess文件正常工作。相反,我使用了以下的解决方法:

www.domain.com处的html索引文件在检测到m.domain.com时将移动用户重定向到screen.width <= 1024px

<script type="text/javascript">
if (screen.width <= 1024) {
    document.location = "http://m.spotlightfoto.nl";
}
</script>

只有索引的移动版本位于m.domain.com,并通过在www.domain.com的最顶层添加<base href>链接到<head>的所有资源<base href="http://www.domain.com">

index.html

我发布此信息以供将来参考。 也许它不是最有效或最精简的方式,但它确实给出了预期的结果。缺点是在将移动用户重定向到移动域之前首先转到常规while True: numb = int(input("number")) if numb % 2 == 0: print("this number is even") elif numb % 2 != 0: print("this number is odd") elif numb == '': break 添加请求。