Marios Mi Marios Mi - 3 months ago 11
Apache Configuration Question

Rewrite dynamic pages AND non-www to www (.htaccess)

Ok, so I have a page.php placed on www.example.com/test that I want to rewrite to www.example.com/test/page/id ( from www.example.com/test/page.php?page=id )

I added this simple .htaccess and everything's fine so far

Options +FollowSymLinks
RewriteEngine on
RewriteRule page/(.*)/ page.php?page=$1
RewriteRule page/(.*) page.php?page=$1


The thing though is that I also want to redirect example.com/test/page/id to www.example.com/test/page/id

Is this possible to do? I tried adding a RewriteCond but it messed it up more.

Thanks in advance

Answer

I haven't paid attention to your question please try this, I've tested it, put this in exact same manner with [L,R] flag

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteRule page/(.*)/ page.php?page=$1
RewriteRule page/(.*) page.php?page=$1