How to redirecting non-www to www with .htaccess for all page's? in my main page(index) works, but if i go mywebsite.com/page2, will not redirect me to my preference domain www.mywebsite.com/page2. How can i fix it?

Recommended Answers

All 12 Replies

There are several examples all over the internet. if you just perform a quick search, you'd find them.

here is one example...

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Yes man i know that, but works just from index page, if i type myweb.com/page1 dosen't redirect me to www.myweb.com/page1

it may be helpful if show your rule(s).

the $1 parameter passes everything after .com to the rewritten url
it should work
except when something is missed or changed on the server config.
many servers are locked down, and if the locking is . .. . less than perfect . ..
try

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

which covers the more common apache config errors

one stupid little carat

Hi again, i use this

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com[nc]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]

And almostbob i try your version but still dosen't work.

then its not an apache config error
your code is not good

line 4, there should not be a nocase [NC] flag it should be L,
rewrite condition in line 3 creates an infinite loop
search for mysite.com in the host string, redirect to www
then do it again to the redirect url, and again and again

the code samples given all have a rewrite condition
RewriteCond %{HTTP_HOST} !^www\.
search for url that do NOT include www., and redirect to www.

Soo how i can redirect each page separately?

Give me an exemple for: mywebsite.com/page1

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.site/$1 [R=301,L]

I assume you replaced 'site' with your site name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.