0

I want redirect all traffic to example.com/* to be redirected to www.example.com/*

I found How can I redirect any ServerAlias to the respective ServerName? which handles the topic in question and did what was recommended in the answer with four upvotes:

RewriteEngine On
RewriteCond %{HTTP_HOST}  !^www.example.com [nocase]
RewriteRule ^(.*)$        http://www.example.com$1 [last,redirect=301]

However, this redirect traffic going to http://example.com/subdirectory to http://www.example.com and not to http://www.example.com/subdirectory as desired.

Any medication on this issue?

BudwiseЯ
  • 125
  • 1
  • 6

1 Answers1

2

The correct way to do this is to create a new vhost and redirect in that:

<VirtualHost *:80>
  ServerName example.com
  Redirect / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www/something
</VirtualHost>
adaptr
  • 16,479
  • 21
  • 33