Crayl
Crayl

Reputation: 1911

htaccess - Why aren't my rewrite rules working?

There's some misconfiguration in my htaccess which I can't solve :/

Here's the htaccess:

RewriteEngine on
RewriteRule ^([^\.]+)/?$ index.php?page=$1 

rewritecond %{http_host} ^domain.com [NC]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,L]

The .htaccess actually works fine, except in one case: When I connect to a subpage to the root domain without "www.", like this:

http://domain.com/somestuff

Then the first rule doesn't apply and I get redirected to:

http://www.domain.com/index.php?page=somestuff

What have I done wrong?? Thanks for any suggestions!

Upvotes: 0

Views: 80

Answers (1)

slattman
slattman

Reputation: 88

Try moving

RewriteRule ^([^\.]+)/?$ index.php?page=$1

below

RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]

Upvotes: 1

Related Questions