我已经设置了通配符子域并且可以正常工作,现在我希望在thats子域中拥有朋友的内容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
我有下一个.htaccess
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 /内容标题,我需要$ _GET(idP)
我真的很喜欢这个东西,我不是htaccess的专家,在此先感谢大家。
有两个问题:
RewriteRule
目录的斜杠之后.htaccess
和查询字符串之前的所有内容的match的第一个参数。如果.htaccess
在您的www根目录中,并且您获得url http://www.example.com/shiny/unicorns.php?are=shiny
,则将与匹配shiny/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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句