logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.



Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Non WWW to WWW redirection - Help required
Author
solorize



Joined: 16 Nov 2019
Posts: 2
Location: UK, London

PostPosted: Sat 16 Nov '19 18:05    Post subject: Non WWW to WWW redirection - Help required Reply with quote

Hi

I wonder if someone can help me with the below query;

I am trying to set up NON-WWW to WWW redirection.
I have tried various examples that I have found
on numerous forums/website, but non seem to work.

F.Y.I
I am running Apache version: 2.2.25 (Win32)

I have the following line un-commented in my httpd.conf file;

LoadModule rewrite_module modules/mod_rewrite.so



Various options of code that I have tried in my .htaccess file are;

Option 1.
Code:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]


Option 2.
Code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]


Option 3.
Code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) https://www.example.com/$1 [R=301,L]


Option 4.
Code:

RewriteEngine on
RewriteBase /
RewriteCond %{http_host} !^www.example.com$ [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc,L]


Non of which have worked.

As my domain is: lmp.d2g.com (I replace the'example.com' with this
in all of the above examples), could it be causing problems
due to it having the additional '.' between lmp and d2g?

If someone could confirm exactly how to set this up correctly
and explain which files I need to edit and what with,
I would be very grateful, as no matter what I do I cannot get it to work.

If you need anymore information please let me know.

Thanks in advance
Question
Back to top
bagu



Joined: 06 Jan 2011
Posts: 153
Location: France

PostPosted: Sun 17 Nov '19 22:41    Post subject: Reply with quote

Here is what i use (in my vhost config) :

Code:

   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^example.com [NC]
   RewriteRule ^ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


Hope it can help
Back to top
solorize



Joined: 16 Nov 2019
Posts: 2
Location: UK, London

PostPosted: Mon 18 Nov '19 15:41    Post subject: Reply with quote

Hi Bagu,

Thank you for your reply.

Can I just confirm that the vhost config file is this one located here:

Apache2.2/config/extra/httpd-vhosts.conf


Also, do I need to put your code within a tag?
i.e.

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
Back to top
bagu



Joined: 06 Jan 2011
Posts: 153
Location: France

PostPosted: Tue 19 Nov '19 11:10    Post subject: Reply with quote

Hello,

The answer to both of your questions is yes.

However, I did not read well.
I did not see that you were under Apache 2.2 and not 2.4.
Likewise, you must indicate other basic elements in your Vhost. (Servername and DocumentRoot at least)
Back to top


Reply to topic   Topic: Non WWW to WWW redirection - Help required View previous topic :: View next topic
Post new topic   Forum Index -> Apache