通过htaccess的动态子域+定义子域

编程入门 行业动态 更新时间:2024-10-18 12:26:48
本文介绍了通过htaccess的动态子域+定义子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我讨厌问mod_rewrite的问题,但我似乎无法得到这些规则正常工作。我有它设置和揣摩过一次,但几年过去了,现在它只是没有发挥很好,我的mod_rewrite的知识是回到Joey:嗯......

从本质上讲就是我想要做的是对的主域名,example力WWW。 (或者强迫任何WWW甚至会更好,但我没有远程能够得到的正常工作以及动态子域)。

如果存在my.example规则,然后按照它们相应的

为别的,即:* .example的,传递到另一个文件解析

规则我已经当前处理迫使WWW,妥善处理动态子域,但完全忽略my.example规则,处理它作为通配符子域。看来我可以得到我的任何一个规则工作正常,但试图让他们一起工作,它只是作为一个混蛋的时候。如果有人知道要得到这个工作正常,将是超级AP preciated。

选项+了FollowSymLinks RewriteEngine叙述上 的RewriteBase / #在主力WWW,没有强制的www会更好。 的RewriteCond%{HTTP_HOST}!^(。*)\。example $ [NC] 重写规则^(。*)$ www.example/$1 [R = 301,L] #my.example定义子域名 的RewriteCond%{HTTP_HOST} ^!我\ .EXAMPLE \ .COM $ [NC] 。重写规则^ * $ - [S = 3] 重写规则^ $ /mydirectory/index.php [L] 重写规则^类/([^ /] +)/ $ /mydirectory/index.php?category=$1 [L] 重写规则^递交/?$ /mydirectory/process.php [L] #* .example的 的RewriteCond%{HTTP_HOST} ^(。*)\。com $ [NC] 的RewriteCond%1!^(WWW)\。例子$ [NC] 重写规则^([^ /] +)/ $ /subdomainparse/index.php?subdomain=%1&fakedirectory=$1 [L]

解决方案

请尝试以下规则:

在主#删除WWW 的RewriteCond%{HTTP_HOST} ^ WWW \ .EXAMPLE \ .COM $ [NC] 重写规则^(。*)$ example/$1 [R = 301,L] #my.example定义子域名 的RewriteCond%{HTTP_HOST} ^!我\ .EXAMPLE \ .COM $ [NC] 。重写规则^ * $ - [S = 3] 重写规则^ $ /mydirectory/index.php [L] 重写规则^类/([^ /] +)/ $ /mydirectory/index.php?category=$1 [L] 重写规则^递交/?$ /mydirectory/process.php [L] #* .example的 的RewriteCond%{HTTP_HOST} ^(。*)\。例如\ .COM $ [NC] 的RewriteCond%1!^ WWW $ [NC] 重写规则^([^ /] +)/ $ /subdomainparse/index.php?subdomain=%1&fakedirectory=$1 [L]

第一条规则现在将重定向+ www.example *来的 example 的。而第三条规则将捕获任何请求一个不存在的主机。

I hate asking questions about mod_rewrite, but I can't seem to get these rules working properly. I had it setup and figured out once before, but a few years have passed and now it's just not playing nice and my mod_rewrite knowledge is back to uhhhh......

Essentially what I want to do is force www on the main domain, example. (or forcing no www would be even better, but I haven't remotely been able to get that working properly along with dynamic subdomains).

If my.example rules exist, then follow them accordingly

For anything else, ie: *.example, pass to another file to parse.

The rules I have currently handles forcing the www, and properly handles the dynamic subdomain, but completely ignores my.example rules, handling it as a wildcard subdomain. It seems I can get any one of my rules working properly, but when trying to get them working together it's just being a bastard. If anyone knows have to get this working properly it would be super appreciated.

Options +FollowSymLinks RewriteEngine On RewriteBase / # force www on main, force no www would be better. RewriteCond %{HTTP_HOST} !^(.*)\.example$ [NC] RewriteRule ^(.*)$ www.example/$1 [R=301,L] # my.example defined subdomain RewriteCond %{HTTP_HOST} !^my\.example\$ [NC] RewriteRule ^.*$ - [S=3] RewriteRule ^$ /mydirectory/index.php [L] RewriteRule ^category/([^/]+)/?$ /mydirectory/index.php?category=$1 [L] RewriteRule ^submit/?$ /mydirectory/process.php [L] # *.example RewriteCond %{HTTP_HOST} ^(.*)\$ [NC] RewriteCond %1 !^(www)\.examples$ [NC] RewriteRule ^([^/]+)/?$ /subdomainparse/index.php?subdomain=%1&fakedirectory=$1 [L]

解决方案

Try these rules:

# remove www on main RewriteCond %{HTTP_HOST} ^www\.example\$ [NC] RewriteRule ^(.*)$ example/$1 [R=301,L] # my.example defined subdomain RewriteCond %{HTTP_HOST} !^my\.example\$ [NC] RewriteRule ^.*$ - [S=3] RewriteRule ^$ /mydirectory/index.php [L] RewriteRule ^category/([^/]+)/?$ /mydirectory/index.php?category=$1 [L] RewriteRule ^submit/?$ /mydirectory/process.php [L] # *.example RewriteCond %{HTTP_HOST} ^(.*)\.example\$ [NC] RewriteCond %1 !^www$ [NC] RewriteRule ^([^/]+)/?$ /subdomainparse/index.php?subdomain=%1&fakedirectory=$1 [L]

The first rule will now redirect the +www.example* to example. And the third rule will catch any request to a non existing host.

更多推荐

通过htaccess的动态子域+定义子域

本文发布于:2023-10-31 16:06:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:义子   动态   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!