Forum Moderators: phranque
I'm trying to keep all access to any file on my website to go through the www subdomain. All my URLs are already being generated using the www, but it doesn't prevent people from accessing the site without the www.
I've tried to solve this in the past, and always get frustrated and give up. I'm currently using this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The problem with this is very annoying. If I go to a URL such as example.com/folder/file.ext, I get redirected to www.example.com/file.ext.
If I go to example.com/folder, I get redirected to www.example.com. If I go to example.com/folder/, I get redirected properly.
Is there a way out there, to simply add the www. to the beginning of the URL, and keep the full path, with all parameters intact? This site uses many levels and is dynamically created, and I can't have users being redirected to the root when the server attempts to fix an access problem on their end.
Much thanks for any help!
You've likely got some other mod_rewrite rules or mod_alias directives that are interfering -- in this .htaccess file or in subdirectory .htaccess files, or in server config-level files such as httpd.conf or conf.d, etc.
This problem could also be caused by mod_negotiation (Options +MultiViews) or by 'AcceptPathInfo on'.
But you may not be able to just disable the other function(s) to stop the interference -- Your complex site may require those features.
Jim
As for the server-level configuration, I can't verify that myself. This site is hosted on a shared server. Is there any way that I can confirm other settings, and possibly override them?
If I can't, what should I ask my hosting company to do in order to enable the functionality I've described?
Thank you for your reply.
Options -MultiViews
This can be combined with your existing +FollowSymLinks Option, as in
Options +FollowSymLinks -MultiViews
AcceptPathInfo off
Jim