【问题标题】:Mod_rewrite .htaccess subdomain but differentiate between clean subdomain and pathed URLMod_rewrite .htaccess 子域,但区分干净的子域和路径 URL
【发布时间】:2013-12-02 11:12:20
【问题描述】:

我如何 mod_rewrite(在 .htaccess 中)来做到这一点?

{subdomain}.thedomain.com

{subdomain}.thedomain.com/

……应该改写为:

thedomain.com/index.php?do={subdomain}

....但是,所有其他文件或目录都应在没有子域部分的情况下重写,其余部分保持原样。 例如

xyz.thedomain.com/something/somethingelse/somefile.jpg 

----------->

thedomain.com/something/somethingelse/somefile.jpg

【问题讨论】:

    标签: apache .htaccess mod-rewrite wildcard subdomain


    【解决方案1】:

    只要您的子域与主域指向同一个文档根目录,您所需要做的就是将这些规则添加到文档根目录中的 htaccess 文件中。

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ^([^.]+)\.thedomain\.com$ [NC]
    RewriteRule ^(.+)$ http://thedomain.com/$1 [L,R=301]
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ^([^.]+)\.thedomain\.com$ [NC]
    RewriteRule ^/?$ /index.php?do=%1 [L]
    

    【讨论】:

      猜你喜欢
      • 2012-01-27
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 2012-05-28
      • 2016-07-06
      相关资源
      最近更新 更多