[SOLVED] How can I redirect my non www URL to my www site?

Hi there,

I’ve given up on trying to do this in my .htaccess file and I’d like to try to do this through Webmin.
Could you please tell me how to do this redirection please?

I know it’s in the Aliases and Redirects section of Apache, but I need some instructions please.

Thank you

In two ways:

  • Create .htaccess and put inside
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

  • Use Apache and under virtualhost:80 add/change
    ServerName example.com
    Redirect permanent / http://www.example.com/

Hi and thanks for your response.

I already had something similar in both my .htaccess and the “Alias and Redirects” section of Webmin.
I was hoping that your code would solve the problem but unfortunately it persists.

I get this weird code:

Index of /

Index of /

[ICO] Name Last modified Size Description


Which looks like this: https://s32.postimg.org/3l1rackp1/Capture.png

Any ideas as to what could be going on?

Thank you

You should reset everything back to default values (including Aliases and Redirects) and then try with my suggestion. When i can i always prefer Apache but you can choose what you think it will be better in your case, just remember there is no need to have both.

About “Aliases and Redirects” i never used so i dont know how it works and if it works.

Well, after much searching I figured out that what was being served was a cached mod_pagespeed page.
So I cleared the cache with touch /var/cache/mod_pagespeed/cache.flush and it works.

Thanks for your help.