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
  • 180
  • 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,426
  • 10
  • 37
  • 45
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
  • 40,709
  • 21
  • 93
  • 115
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,497
  • 1
  • 11
  • 20