2017-05-09 8 views
1

Ich muss meine symfony-Website von "abc.com" zu "www.abc.com" umleiten. Ich habe versucht, einige Lösungen in Stack-Überlauf, aber sie fügen mehrere "www." an die Adresse und andere hat nicht funktioniert.Symfony2 - Umleitung von nicht-www zu www

Hier ist meine Htaccess Quelle.

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> 

Wie kann ich das tun?

+0

Mögliche Duplikat [htcaccess und Symfony 2 nicht www umleiten -> www] (https://stackoverflow.com/questions/27398989/htcaccess-and -symfony-2-redirect-non-www-www) – Trix

Antwort

7

Fügen Sie die folgende Regel als erste Regel:

RewriteCond %{HTTP_HOST} !^(www)\. 
RewriteRule ^(.*?)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
+0

Danke, es hat funktioniert. – TechyTee

Verwandte Themen