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

5 posts / 0 new
Last post
#1 Mon, 06/06/2016 - 15:17
No Expert

[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

Mon, 06/06/2016 - 18:20
Diabolico
Diabolico's picture

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/

- I often come to the conclusion that my brain has too many tabs open. -
Failing at desktop publishing & graphic design since 1994.

Tue, 06/07/2016 - 15:39
No Expert

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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
  <title>Index of /</title>
</head>
<body>
<h1>Index of /</h1>
<table><tr><th><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr><tr><th colspan="5"><hr></th></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>

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

Any ideas as to what could be going on?

Thank you

Tue, 06/07/2016 - 18:07
Diabolico
Diabolico's picture

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.

- I often come to the conclusion that my brain has too many tabs open. -
Failing at desktop publishing & graphic design since 1994.

Fri, 06/10/2016 - 15:41
No Expert

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.

Topic locked