.htaccess 通配符子域htacces上的好友url,不起作用

.htaccess 通配符子域htacces上的好友url,不起作用,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我已经有了通配符子域集,并且工作正常,现在我希望有朋友的url作为子域中的内容,我的网站的结构是如果用户类型为subdomain.maindomain.com和.htaccess重定向到 blogs/index.php?user=subdomain 其中blogs/index.php接收参数并显示正确的内容 现在我试着让url函数如下 subdomain.maindoamin.com/24/title-of-content 然后,必须生成.htaccess blogs/index.php?i

我已经有了通配符子域集,并且工作正常,现在我希望有朋友的url作为子域中的内容,我的网站的结构是如果用户类型为subdomain.maindomain.com和.htaccess重定向到

blogs/index.php?user=subdomain
其中blogs/index.php接收参数并显示正确的内容

现在我试着让url函数如下

subdomain.maindoamin.com/24/title-of-content
然后,必须生成.htaccess

blogs/index.php?id_content=24&title=title-of-content
我有下一个访问权限

Options +FollowSymLinks

#this force to server the content always without www.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [R=301]

#this is to pass the subdomain like param and show the right content of the user
RewriteCond %{HTTP_HOST} !^www\.misite\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.misite\.com
RewriteRule ^(.*)$ blogs/index.php?url=%1 [QSA,L]

#the next line i can't make work to make nice url
RewriteRule ^/(.*)/(.*)$ blogs/index.php?idP=$1&name=$2 [L]
不工作,因为当我在index.php中

echo $_SERVER['REQUEST_URI'];
不显示idP=24显示/24/内容标题,我需要$\u获取(idP)


我真的很感谢大家对这件事的一些了解,我不是htaccess方面的专家,提前感谢大家

有两个问题:

  • RewriteRule
    的第一个参数与目录
    .htaccess
    斜杠后面的所有参数匹配,位于查询字符串之前。如果
    .htaccess
    在您的www根目录中,并且您得到了url
    http://www.example.com/shiny/unicorns.php?are=shiny
    ,您可以与
    shinny/unicorns.php
    进行匹配。它永远不会以斜杠开头,因此
    ^/
    永远不会匹配
  • 规则是按顺序执行的。如果您转到
    http://sub.example.com/10/unicorns
    ,第二条规则将首先匹配,并将请求重写为
    /blogs/index.php?url=10/unicorns
    。如果删除了前导斜杠,则第三条规则将匹配,但通常情况下,您不希望这样。您只希望第三条规则匹配
  • 您希望将第三条规则向上移动,使其成为第二条规则。您希望使其更具体,只与子域匹配。您还知道第一部分只包含数字,所以使用这些知识来防止
    blogs/index.php
    与您现在的第二条规则相匹配。您还需要防止blogs/index.php与现在的第三条规则匹配,以防止它与自身匹配。最后但并非最不重要的一点是,我从现在的第二条规则中删除了
    [L]
    ,因为第三条规则无论如何都会匹配

    #the next line i can't make work to make nice url
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^([0-9]+)/([^/]+)$ blogs/index.php?idP=$1&name=$2
    
    #this is to pass the subdomain like param and show the right content of the user
    RewriteCond %{HTTP_HOST} !^www\.misite\.com [NC]
    RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.misite\.com
    RewriteCond %{REQUEST_URI} !/blogs/index\.php
    RewriteRule ^ blogs/index.php?url=%1 [QSA,L]
    

    请阅读。特别是说“•删除的前缀总是以斜杠结尾,这意味着匹配发生在从不具有前导斜杠的字符串上。因此,在每个目录上下文中具有^/从不匹配的模式。”此外,
    RewriteRule
    也会按其出现的顺序执行。第二条规则在您希望与第三条规则匹配的情况下始终匹配。切换这两个,所以更具体的一个是第一个。嗨!谢谢你已经阅读了你给我的链接,所以我的htaccess有一个新的RewriteCond RewriteCond%{REQUEST_URI}^(.*)/(.*)$[NC]RewriteRule^(.*)/(.*)$blogs/index.php?idP=$1&name=$2[QSA]但是仍然不起作用,我做错了什么?另外,我删除了第二条规则的[L],我正在使用此工具进行测试,我还更改了第二条规则,如RewriteRule^(.*)\.misite\.com$blogs/index.php?url=%1[QSA],但通配符子域不再工作。
    %{REQUEST\u URI}
    以斜杠开头,而且
    RewriteRule
    的第一个参数不能用于匹配域名。非常感谢Sumurai8,这是我第一次处理复杂的htaccess,是的,更改规则工作的级别,您的解决方案工作出色,非常感谢,您是否建议我使用一些文档来了解更多关于htaccess的重写规则?再次感谢