【问题标题】:How to configure .htaccess in this way?如何以这种方式配置.htaccess?
【发布时间】:2012-07-09 08:10:37
【问题描述】:

我已成功安装通配符。我设法让动态子域使用一个简单的技巧。

.htaccess:

Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /

        # *.example.com
        RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
        RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.example\.com$ [NC]
        RewriteCond %{REQUEST_URI} !^/?subdomain\.php$
        RewriteRule .? subdomain.php?subdomain=%1&path=%{REQUEST_URI} [L,QSA]

目前在something.example.com 中显示了subdomain.php 的输出,太好了。

但我想让它工作,因为我可以在

输入

pre102.example.com/folder/anotherfolder/script.php?param=1

并显示

的输出

example.com/folder/anotherfolder/script.php?param=1&pre=102

【问题讨论】:

  • 所以你想让pre102.example.com/folder/anotherfolder/script.php?param=1重定向到example.com/folder/anotherfolder/script.php?param=1&pre=102(意思是它改变了浏览器的地址栏)?
  • 不,浏览器的栏不应该改变。
  • pre102.example.com 和 example.com 是否来自同一个文档根目录?

标签: apache .htaccess subdomain wildcard-subdomain


【解决方案1】:
RewriteCond %{QUERY_STRING} !pre=[0-9]
RewriteCond %{HTTP_HOST} ^pre([0-9]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /$1?pre=%1 [L,QSA]

【讨论】:

  • 这不起作用。它将我重定向到 pre.example.com 并显示 example.com 的内容
  • 对不起,这很好用。我在跨子域共享 php 会话时遇到了问题。解决了stackoverflow.com/a/1457582/1502554
猜你喜欢
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-12
  • 2016-02-12
  • 1970-01-01
  • 2018-09-02
  • 2017-06-16
相关资源
最近更新 更多