【问题标题】:How to add .htaccess URL mask so that specific pages are shown to be under subdomain如何添加 .htaccess URL 掩码,以便将特定页面显示在子域下
【发布时间】:2018-04-23 13:35:53
【问题描述】:

我的网站有一些页面:

http://example.com/myuglyurl.php?id=11
http://example.com/myuglyurl.php?id=12
http://example.com/myuglyurl.php?id=13

而且,对于某些页面,我希望我的用户在他们的浏览器中看到他们在子域中,例如:

http://example.com/myuglyurl.php?id=11
http://mynewsubdomain.example.com/myuglyurl.php?id=12
http://example.com/myuglyurl.php?id=13

子域存在,当用户直接尝试访问子域时,我会将它们重定向到特定页面,没问题。但是网址掩码我做不到。

我尝试过各种 .htaccess 技巧,但由于我对 .htaccess 完全陌生,我无法做到。

我试过了:

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)id=12($|&)
RewriteRule ^myuglyurl\.php$ http://mynewsubdomain.example.com/myuglyurl.php?%{QUERY_STRING}

但我得到一个空白页面,并显示消息:找不到文件。

【问题讨论】:

    标签: .htaccess subdomain url-masking


    【解决方案1】:

    请使用以下内容。

    重定向并保留 URL 之后的所有内容 访问 yourdomainA.com/page,它将显示 yourdomainB.com/page 中的内容

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^yourdomainA.com
    RewriteRule ^(.*) http://www.yourdomainB.com/$1 [P]
    

    更多详情请参考此链接-https://www.brontobytes.com/knowledgebase/202/htaccess-URL-Masking-Examples.html

    【讨论】:

      猜你喜欢
      • 2012-09-08
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多