.htaccess的子域名规则 [英] Htaccess subdomain rules

查看:241
本文介绍了.htaccess的子域名规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用htaccess的一组规则来控制不同的网页我的网站。

  1. 如果用户访问我的主网站(domain.com),而不使用万维网是301重定向到www.domain.com(搜索引擎优化的目的)
  2. 在我使用通配符子域,因此,如果用户访问subdomain.domain.com,他们会查看决定内容为他们特定的PHP文件。

我的问题是,我想延长我的设置,以便能够使用相同的URL名称。就好像我访问subdomain.domain.com/feed一个例子,我会看到从主域规则页/ public_news_feed.php文件,因为它共享/饲料的规则。我真正想要的送达是页/ public_subdomain_blog_feed.php!

如何为domain.com和subdomain.domain.com我可以设置特定的规则?

在此先感谢,并有一个美好的一天!

  #AuthName禁区
#AuthType基本
#AuthUserFile /var/www/user/data/www/domain.com/.htpasswd
#require有效的用户

选项​​+的FollowSymLinks
RewriteEngine叙述上

#force域设置为使用WWW
的RewriteCond%{HTTP_HOST} ^域\ .COM $ [NC]
重写规则^(。*)$ http://www.domain.com/$1 [R = 301,L]

#REDIRECT子域控制器
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^ $页/ public_subdomain_blog.php [L,QSA]

的RewriteCond%{REQUEST_URI}!-f
重写规则^(indsend-nyhed)$页/ public_submit_news.php [L]
重写规则^(modeblogs)$页/ public_blogs.php [L]
重写规则^(nyheder)$页/ public_news.php [L]
重写规则^(饲料)$页/ public_news_feed.php [L]
重写规则^(nyheder)/([0-9] *)/(。*)$页/ public_news_single.php?N_ID = $ 2 [L]
重写规则^(kontrolpanel)$页/ private_account.php [L,QSA]
重写规则^(kontrolpanel)/(logud)$页/ private_logout.php [L]


##这些规则应该只能设置如果用户是一个子
重写规则^([0-9] *)/(。*)$页/ public_subdomain_blog_article.php?P_ID = $ 1 [L]
重写规则^(驾驶员学校)/([0-9] *)$页/ public_subdomain_blog.php?C_ID = $ 2 [L]
重写规则^(ARKIV)/([0-9] *)$页/ public_subdomain_blog.php?A_ID = $ 2 [L]
重写规则^(饲料)$页/ public_subdomain_blog_feed.php [L]
 

解决方案

好了,你已经知道如何调节用户是否是一个子域,因为你做了你的控制器已经:

 的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^ $页/ public_subdomain_blog.php [L,QSA]
 

虽然它可能是也可能不是可以简化您的整个规则集一点,做最简单的事情是只调节你的规则以同样的方式。既然你有较少的子域名的规则,我们可以将上述主网站的规则和条件适用的重写,使用你具备的条件:

  ##,这些规则应该只能设置如果用户是一个子
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^([0-9] *)/(。*)$页/ public_subdomain_blog_article.php?P_ID = $ 1 [L]
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^(驾驶员学校)/([0-9] *)$页/ public_subdomain_blog.php?C_ID = $ 2 [L]
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^(ARKIV)/([0-9] *)$页/ public_subdomain_blog.php?A_ID = $ 2 [L]
的RewriteCond%{HTTP_HOST}!^(WWW \)?域\ .COM $ [NC]
重写规则^(饲料)$页/ public_subdomain_blog_feed.php [L]

的RewriteCond%{REQUEST_URI}!-f
重写规则^(indsend-nyhed)$页/ public_submit_news.php [L]
重写规则^(modeblogs)$页/ public_blogs.php [L]
重写规则^(nyheder)$页/ public_news.php [L]
重写规则^(饲料)$页/ public_news_feed.php [L]
重写规则^(nyheder)/([0-9] *)/(。*)$页/ public_news_single.php?N_ID = $ 2 [L]
重写规则^(kontrolpanel)$页/ private_account.php [L,QSA]
重写规则^(kontrolpanel)/(logud)$页/ private_logout.php [L]
 

I use htaccess with a set of rules to control the different pages of my website.

  1. If a user visits my main site (domain.com), without using www it 301 redirects to www.domain.com (for SEO purposes)
  2. I use wildcard subdomains, so if a user visits subdomain.domain.com, they will view a specific PHP file that decides to content for them.

My problem is that I would like to extend my setup, to be able to use the same url names. As an example if I visit subdomain.domain.com/feed, I will see pages/public_news_feed.php file from the main domain rule, since it shared the "/feed" rule. What I really wanted to be served is pages/public_subdomain_blog_feed.php!

How can I setup specific rules for domain.com and subdomain.domain.com?

Thanks in advance and have a wonderful day!

#AuthName "Restricted Area" 
#AuthType Basic
#AuthUserFile /var/www/user/data/www/domain.com/.htpasswd 
#require valid-user

Options +FollowSymLinks
RewriteEngine on

#force domain setup to use www
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

#redirect subdomains to controller
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^$ pages/public_subdomain_blog.php [L,QSA]

RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(indsend-nyhed)$           pages/public_submit_news.php [L]
RewriteRule ^(modeblogs)$               pages/public_blogs.php [L]
RewriteRule ^(nyheder)$             pages/public_news.php [L]
RewriteRule ^(feed)$                    pages/public_news_feed.php [L]
RewriteRule ^(nyheder)/([0-9]*)/(.*)$       pages/public_news_single.php?n_id=$2 [L]
RewriteRule ^(kontrolpanel)$                pages/private_account.php [L,QSA]
RewriteRule ^(kontrolpanel)/(logud)$            pages/private_logout.php [L]


## THESE RULES SHOULD ONLY BE SET IF THE USERS IS ON A SUBDOMAIN
RewriteRule ^([0-9]*)/(.*)$         pages/public_subdomain_blog_article.php?p_id=$1 [L]
RewriteRule ^(kategori)/([0-9]*)$       pages/public_subdomain_blog.php?c_id=$2 [L]
RewriteRule ^(arkiv)/([0-9]*)$      pages/public_subdomain_blog.php?a_id=$2 [L]
RewriteRule ^(feed)$                pages/public_subdomain_blog_feed.php [L]

解决方案

Well, you already know how to condition on whether the user is on a subdomain, since you do it for your controller already:

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^$ pages/public_subdomain_blog.php [L,QSA]

While it may or may not be possible to simplify your entire ruleset a bit, the easiest thing to do is to just condition your rules in the same way. Since you have fewer subdomain rules, we can move those above your main site rules and apply the rewrites conditionally, using the condition you have:

## THESE RULES SHOULD ONLY BE SET IF THE USERS IS ON A SUBDOMAIN
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^([0-9]*)/(.*)$       pages/public_subdomain_blog_article.php?p_id=$1 [L]
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(kategori)/([0-9]*)$ pages/public_subdomain_blog.php?c_id=$2 [L]
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(arkiv)/([0-9]*)$    pages/public_subdomain_blog.php?a_id=$2 [L]
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(feed)$              pages/public_subdomain_blog_feed.php [L]

RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(indsend-nyhed)$         pages/public_submit_news.php [L]
RewriteRule ^(modeblogs)$             pages/public_blogs.php [L]
RewriteRule ^(nyheder)$               pages/public_news.php [L]
RewriteRule ^(feed)$                  pages/public_news_feed.php [L]
RewriteRule ^(nyheder)/([0-9]*)/(.*)$ pages/public_news_single.php?n_id=$2 [L]
RewriteRule ^(kontrolpanel)$          pages/private_account.php [L,QSA]
RewriteRule ^(kontrolpanel)/(logud)$  pages/private_logout.php [L]

这篇关于.htaccess的子域名规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆