Apache针对特定页面的重写规则问题


apache rewrite rules issue for specific pages

我的。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
) 

我错过了什么?

试试这个规则:

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]用于查询字符串追加。

您需要按照以下方式重写about和contact规则:

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