Luka
Luka

Reputation: 321

Always WWW modrewrite php

I want to force www in my urls. I'm having problems with writing. I know that this code will do the trick.

RewriteCond %{HTTP_HOST} ^example.com 
RewriteRule ^(.*)$ http://www.example.com/$1

But I want to put all in $_GET['page']

RewriteRule ^(.*)$ /index.php?page=$1 [L]

How should I put this together?

Upvotes: 0

Views: 169

Answers (2)

Szymon Lukaszczyk
Szymon Lukaszczyk

Reputation: 722

this should do the job

RewriteCond %{HTTP_HOST} ^example.com 
RewriteRule ^(.*)$ http://www.example.com/$1
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* index.php?page=$0 [L]

Upvotes: 1

user142162
user142162

Reputation:

You need to add [QSA], which allows you to modify the query string of the URL:

RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]

Upvotes: 2

Related Questions