Gun arves
Gun arves

Reputation: 95

Need www. to rewrite rule .htaccess

I have problem of making my rewrite condition to work. I have this code:

RewriteCond %{HTTP_HOST} ^www\.server\.ee$
RewriteRule ^/?$ "http\:\/\/server\.ee\/" [R=301,L]

It redirects to https://server.ee But i need it to redirect https://www.server.ee

How can I manage that?

Tried

http\:\/www.\/server\.ee\/ 

But nothing, what am i doing wrong?

Upvotes: 0

Views: 24

Answers (1)

Sourov Roy Chowdhury
Sourov Roy Chowdhury

Reputation: 113

This code work for me, you may try with this.

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

Make sure you reset your cache before testing this. You will also notice that I've set R=302, this makes it a temporary redirect for testing purposes, if you're happy this is working then change it to R=301 to make it permanent.

Upvotes: 1

Related Questions