3

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

messinismarios
  • 182
  • 3
  • 12

3 Answers3

1

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
Abhishek Gurjar
  • 7,330
  • 10
  • 37
  • 44
0

To redirect non www requests to www, add the following rule bellow RewriteEngine line in your htaccess

RewriteCond %{HTTP_HOST} !^www
RewriteRule ^ http://www%{HTTP_HOST}%{REQUEST_URI} [L,R]
Amit Verma
  • 39,545
  • 18
  • 87
  • 107
0

Try this

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule page/(.*)/ page.php?page=$1
RewriteRule page/(.*) page.php?page=$1
Sylwit
  • 1,393
  • 1
  • 10
  • 18