How to write a rule in vhost definition file to redirect example.com > www.example.com
I had a rule that redirect example.com > www.example.com. I removed htaccess file and placed rules into a /etc/apache2/sites-available/example virtual host definition file. And basically rule above stopped working.
Here is the code, I would appreciate any help and it would be fun to know why the thing stopped working.
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/symfony/web
<Directory /var/www/symfony/web>
AllowOverride Non开发者_运维问答e
Allow from All
Options FollowSymLinks ExecCGI
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
You may want to just use Redirect in apache instead of messing with .htaccess
. See my answer to a similar question.
精彩评论