问题
I need to redirect my symfony website from "abc.com" to "www.abc.com". I have tried some solutions in stack overflow but they add multiple "www." to the address and others didn't work.
Here is my htaccess source.
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
How can I do this?
回答1:
Add the following rule as the first rule:
RewriteCond %{HTTP_HOST} !^(www)\.
RewriteRule ^(.*?)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
来源:https://stackoverflow.com/questions/43862282/symfony2-redirect-from-non-www-to-www