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?
Yes. In the RewriteCond , it's basically saying that it'll run the rewrite as long as $1 doesn't equal on of the files listed to the right of the condition.
RewriteRule "\.exe" "-" [F] This example uses the "-" syntax for the rewrite target, which means that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.
A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With