代码之家  ›  专栏  ›  技术社区  ›  pbarney

mod_rewrite以显示来自通配符域的重定向

  •  0
  • pbarney  · 技术社区  · 14 年前

    我要把mod重写版踢到路边。说“和别人相处不好”,有没有巫医能帮我?

    我设置了通配符DNS来标识用户。我想从:

    http://username.domain.com/foo/bar

    到:

    https://www.domain.com/qux/waldo/username/foo/bar

    这有可能吗?

    我正在开发codeigner,它已经在.htaccess中有了自己的mod重写指令,可以去掉index.php。

    以下是我的资料:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.idseal\.local.*$
    RewriteRule (.*) /site/assign/$1
    
    #Removes access to the system folder by users.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Prix Winteroo    14 年前

    第一行验证我们是否在主域上,第二行将匹配是否有WWW,如果有WWW,它将保留在%1上,因此如果有inst不做任何更改,数据将被写入%2,并将被重写。

    我不能百分之百地肯定这能满足你的需要,但是试着把它报告回去,我会尽我所能帮助你。

    RewriteEngine on
    
    RewriteCond %{http_host} !^www.domain.com [NC]
    RewriteCond %{http_host} ^(www.)?([^.]+).domain.com [NC]
    RewriteRule (.*) https://www.domain.com/qux/waldo/%2/$1