特定页面的apache重写规则问题

时间:2011-11-24 18:50:31

标签: php apache .htaccess mod-rewrite

我的.htaccess重定向问题。当我输入:

http://www.domain.com/contact

它转到index.php而不是contact.php

这是我的.htaccess:

Redirect 301 /clients http://clients.domain.com

RewriteEngine On
SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mob\. page=mobile

RewriteBase /
SetEnvIfNoCase User-Agent "^Wget" bad_bo
#etc ... 
Deny from env=bad_bot

RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301]

RewriteRule ^about/?$ about.php 
RewriteRule ^contact/?$ contact.php 

rewriterule ^(.*)$ index.php?subdomain=%{ENV:page}&page=$1 

在我的php中我得到:

<?php

print_r($_GET);
Array (
  [subdomain] => www
  [page] => contact.php
) 

我错过了什么?

2 个答案:

答案 0 :(得分:17)

尝试此规则:

RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteRule ^about/?$ about.php [NC,QSA,L]
RewriteRule ^contact/?$ contact.php [NC,QSA,L]

rewriterule ^([a-z0-9]+)$ index.php?subdomain=%{ENV:page}&page=$1 [NC,QSA,L]

我还添加了NC, QSA, L标志,以确保匹配时执行最后一条规则[L],非案例[NC]和查询字符串附加[QSA]

答案 1 :(得分:0)

您需要按以下方式重写约会和联系人规则:

RewriteRule ^about/?$ about.php [L,QSA]
RewriteRule ^contact/?$ contact.php [L,QSA]