以下是相互冲突的规则
Options +FollowSymLinks
RewriteEngine on
# 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 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 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]
# For Accessing Users Page
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /users.php?user=%1 [L]
对新闻页面和索引页面的调用都进入索引页面。我不知道为什么?
答案 0 :(得分:2)
规则的顺序非常重要 - 现在这两个提到的网址都将由第一条规则提供,该规则会将它们重写为my-index.php
。
您的第一条规则(适用于my-index.php
)过于宽泛 - 即使您按照正确的顺序放置它仍然会将其重写为my-index.php
页面 - 使用.*
模式匹配所有内容时。
考虑到上述情况,请尝试以下规则:
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]
我做了什么:
my-index.php
移到底部; my-news.php
也会被重写)。这些规则可能仍需要一些调整 - 我不知道你在那里有什么样的网站逻辑。