.htaccess tutorial

htaccess Elite


Redirect non-www to www works, but Alias directive ignored

Ask your mod_rewrite and Redirection questions here, and get answers!

Redirect non-www to www works, but Alias directive ignored

Postby identity » 11 May 2008 16:38

I'm currently redirecting all non-www traffic to the www version -- the RewriteRules below work fine. However, if I map a URL using the Alias directive (such as /images), I noticed that the rewrite rules take no effect; the /images URL is accessible with both the www and non-www version instead of redirecting to the www version. Here's my relevant Apache configuration:

Code: Select all
<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

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

  Alias /images /var/www/images
</VirtualHost>


With the above code, all relevant URLs redirect properly to the www version, except when using the /images alias. So the /images alias is available from both of these URLs:

http://example.com/images/
http://www.example.com/images/

The non-www version does not redirect to the www version, but all other URLs and links redirect perfectly. Does anyone know how to fix this? I read about the PT flag but can't seem to get it to work in this context.

Thanks for the help!
identity
 
Posts: 1
Joined: 11 May 2008 16:30

Re: Redirect non-www to www works, but Alias directive ignored

Postby mod_rewrite » 15 May 2008 05:06

Geez that is one I haven't seen before, I don't have a clue.
mod_rewrite
 
Posts: 102
Joined: 30 Oct 2006 19:55


Return to Redirect or Rewrite Questions