开发者

htaccess confilcting rules for two different files

Here are the conflicting rules

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]

The call for the news page and the index page both goes to the index page. i dont know why?


  1. The order of rules is important -- right now both of those mentioned URLs will be served by the first rule which will rewrite them to my-index.php.

  2. Your first rule (for my-index.php) is too broad -- even if you place it in correct order it will still rewrite it to the my-index.php page -- as you matching everything using .* pattern.

Considering the above try these rules:

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]

What I did:

  • rearranged rules: moved my-index.php one to the bottom;
  • added a condition to not to rewrite requests to existing files (otherwise my-news.php will be rewritten as well).

These rules may still require some tweaking -- I do not know what kind of website logic you have there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜