aki
aki

Reputation: 1241

apache rewrite rules issue for specific pages

I have problem with my .htaccess redirections. When I type:

http://www.domain.com/contact

it goes to the index.php and not the contact.php

here's my .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 

in my php i get:

<?php

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

What am I missing?

Upvotes: 14

Views: 1960

Answers (2)

You need to rewrite your about and contact rules in the following way:

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

Upvotes: 0

Book Of Zeus
Book Of Zeus

Reputation: 49887

Try this rule:

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]

I also added the NC, QSA, L flags to make sure the last rule [L] is executed if match, [NC] for non case and [QSA] for Query String Append.

Upvotes: 17

Related Questions