.htaccess的规则动态子域名冲突的索引文件 [英] Htaccess rules for dynamic sub domain conflicting for index file

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

问题描述

下面是我的htaccess的文件

 选项+了FollowSymLinks
RewriteEngine叙述上

#用于访问页面http://www.domain.com/news/news-details.php
的RewriteCond%{HTTP_HOST} ^ www.domain \ .COM $ [NC]
重写规则^新闻/新闻details.php $ news.php [QSA,NC,L]


#对于www.domain.com就应该到索引页
的RewriteCond%{HTTP_HOST} ^(WWW \)?domain.com $ [NC]
重写规则^(。*)$的index.php [NC,L]
 

当我输入 http://www.domain.com/news/news-details .PHP 它带我到index.php页面,而不是news.php浏览器。为什么?

编辑: 检查这些规则

 #对于www.domain.com就应该到我,index.php页面
#
的RewriteCond%{HTTP_HOST} ^(WWW \)?域\ .COM $ [NC]
重写规则^(。*)$我 - 的index.php [NC,L]


#对于网页网址http://www.domain.com/news/news-details.php
#
的RewriteCond%{REQUEST_URI} ^ /新闻/新闻\ -details \ .PHP [NC]
的RewriteCond%{HTTP_HOST} ^ WWW \。域\ .COM $ [NC]
重写规则^(。*)$我-news.php [NC,QSA,L]
 

解决方案

 选项+了FollowSymLinks
RewriteEngine叙述上

#对于网页网址http://www.domain.com/news/news-details.php
的RewriteCond%{HTTP_HOST} ^ WWW \。域\ .COM $ [NC]
重写规则^新闻/新闻信息\ .PHP $ /my-news.php [NC,QSA,L]

#用于访问分部页http://user1.domain.com/news/news-details.php
的RewriteCond%{HTTP_HOST} ^(。+)\。域\ .COM [NC]
的RewriteCond%{HTTP_HOST)!^ WWW \。
重写规则^新闻/新闻信息\ .PHP $ /my-news.php?user=%1 [QSA,NC,L]

#对于接入用户页面
的RewriteCond%{HTTP_HOST}!^ WWW \。域\ .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^(。*)\。域\ .COM $
重写规则^ $ /users.php?user=%1 [L]

#对于www.domain.com就应该到我,index.php页面
#(但前提是请求的资源是不是真正的文件)
的RewriteCond%{HTTP_HOST} ^(WWW \)?域\ .COM $ [NC]
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^(。*)$ /my-index.php [L]
 

Here is my htaccess file

Options +FollowSymLinks
RewriteEngine on

# For Accessing Page http://www.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^news/news-details.php$  news.php [QSA,NC,L]


# For www.domain.com it should go to the index page
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule ^(.*)$ index.php [NC,L]

when i type http://www.domain.com/news/news-details.php in the browser it takes me to the index.php page rather than news.php. WHY?

EDIT: Check these rule

# For www.domain.com it should go to my-index.php page
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ my-index.php [NC,L]


# For Page URL http://www.domain.com/news/news-details.php
#
RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$  [NC]
RewriteRule ^(.*)$ my-news.php [NC,QSA,L]

解决方案

Options +FollowSymLinks
RewriteEngine On

# For Page URL http://www.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^www\.domain\.com$  [NC]
RewriteRule ^news/news-details\.php$ /my-news.php [NC,QSA,L]

# For Accessing Division Page http://user1.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
RewriteCond %{HTTP_HOST) !^www\.
RewriteRule ^news/news-details\.php$ /my-news.php?user=%1 [QSA,NC,L]

# For Accessing Users Page
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /users.php?user=%1 [L]

# For www.domain.com it should go to my-index.php page
# (but only if requested resource is not real file)
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /my-index.php [L]

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

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