.htaccess - 索引文件动态子域冲突的htaccess规则

标签 .htaccess url-rewriting subdomain

这是我的 htaccess 文件

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]

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

编辑: 检查这些规则

# 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 - 索引文件动态子域冲突的htaccess规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7500829/

相关文章:

apache - 强制删除 .htaccess 中的 .php 扩展名

apache - htaccess : How to redirect from old domain to new with folder condition

php - htaccess 换行崩溃页面

IIS 下的 WCF RESTful Web 服务 - URL 重写(出现 404 错误)

javascript - 跨子域使用 localStorage

node.js - 如何在 Express.js 或 Connect.js 中配置多个子域

java - 在 Google Appengine 上配置 https ://yourdomain. com

apache - htaccess 重定向以排除某些页面

php - 在 php BY .htaccess 中禁用邮件功能

rest - IIS URL 重写 - 反向代理 - 响应 404 错误