reescribir la URL en varios sitios que no sean www

i have some sites they are running with the same files but different templates, my goal is to force use all www or non www domains.

este es mi codigo

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{HTTP:Host} ^[^.]+\.[a-z]{2,5}$ [NC]
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

get it from other question on stackoverflow :)

But if I use www domain all is ok, if not get this redirect

http://domain.de/www/htdocs/user/_production/http%28?s%29://www.

preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

Why not simplify your rules like this:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Respondido 01 Feb 12, 19:02

get server error... not clear what the problem is in this to blocks RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ %{HTTP_HOST} %{REQUEST_URI} [R=301,L] RewriteCond %{HTTPS} =on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ %{HTTP_HOST} %{REQUEST_URI} [R=301,L] - Fribu - Soluciones inteligentes

Actually my bad, there was a space character before %{REQUEST_URI}. I edited it, pls try it again. - anubhava

great, thank you, how can I exclude some subdomains to be redirected? like admin.domain.com - Fribu - Soluciones inteligentes

You're welcome. You can add a RewriteCond line like this: RewriteCond %{HTTP_HOST} !^admin\.domain\.com$ [NC] to avoid redirection for admin.domain.com - anubhava

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.