【问题标题】:Subdomain to MVC url mapping - rewrite matching against multiple rules子域到 MVC url 映射 - 针对多个规则重写匹配
【发布时间】:2016-03-20 13:34:28
【问题描述】:

我想映射
sub1.mydomain.comsub1.mydomain.com/index.php?sub1
sub1.mydomain.com/?aa=bbsub1.mydomain.com/index.php?sub1&aa=bb
sub1.mydomain.com/somethingsub1.mydomain.com/index.php?sub1/something
sub1.mydomain.com/something?aa=bbsub1.mydomain.com/index.php?sub1/somehting&aa=bb
这些也与 sub2.mydomain.com 一起使用。

没有任何重定向,就像 SimpleMVCFramework 对主域所做的一样。 我想使用 sub1.mydomain.com 作为 mydomain.com/sub1 的用户调用的别名(被重写为 mydomain.com/index.php?sub1)的原因。我将两个sub的根目录设置为与主域相同。

这是 .htaccess 代码(位于根目录中),但出现错误 500。

# Map subdomains to controller
RewriteCond %{HTTP_HOST} !^www # if the sub is not www
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com
RewriteCond %{QUERY_STRING} !(sub1|sub2) # preventing loops
RewriteRule ^/?$ /index.php?%1 [NC,QSA,L]  
# this meant to be match if url path is empty eg. sub1.mydomain.com/?aa=bb
RewriteRule ^(.+)$ /index.php?%1/$1 [NC,QSA,L]
# anytime else.

如果我简单地使用第二个角色,(.*) 模式匹配尾部斜杠 (sub1.mydomain.com/index.php?sub1/),(.+) 模式匹配这种方式:sub1.mydomain。 com/index.php?sub1/index.php

提前致谢,
b

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    解决了。

    RewriteConds 仅适用于 RewriteRule 之后的第一个,我需要复制粘贴条件。

    【讨论】:

      猜你喜欢
      • 2017-04-16
      • 2015-09-14
      • 2013-08-14
      • 2014-06-30
      • 2014-06-09
      • 2017-01-15
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多