How to redirect www.subdominio.dominio.com to http://subdominio.dominio.com?

Asked

Viewed 1,870 times

1

In order to allow my domain/hosting to use dynamic subdomains, I had to create a DNS wildcard (domain.Sub.com).

The problem is that some people usually access using the prefix 'www' before the subdomain, so if I try to access my domain in the following way www.subdominio.com will obviously not resolve and will return error in the browser.

It is possible to configure my hosting/domain so that when the user puts the www before the subdomain, it redirects to domain.Sub.com? How?

Example of this is Google Plus, if I access www.plus.google.com will redirect to http://plus.google.com.

  • 1

    How is your wildcard configured in the DNS zone? I have some websites that use dynamic subdomains and DNS zones were simply made like this: * 14400 IN CNAME dominio.com.br. I just tested it and it solves as many levels as you want before the domain for e.g. www.isso.e.um.teste.dominio.com.br so the rewrite rule they posted below would suffice to work...

  • Sorry, I had set up wildcard with type 'A' input and reported the wrong IP, my mistake! Great, now you’re accepting as many levels as you want as subdomain.

  • 1

    This question seems to be decontextualized because it is about a specific user error, which will not help other users, and it seems that it has already been even revoked.

2 answers

2

See if this rule solves

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

Reference!

  • I can’t test it now because my domain is propagating within a few hours. But I think it will not solve because to use mod_rewrite, first you have to treat this problem of mine in the DNS zone. If I put www in front of the domain, will say that the page does not exist or DNS was not found, after I solve this problem, so yes this rule of mod_rewrite will solve, understand?

0

On your DNS provider, add a www.subdominio.com CNAME to Domain.ub.com

  • There is a problem, my domain is dynamic (Wildcard DNS is a record created in the DNS zone that will answer for all requests for non-existent domain names, that is, domain names for which there is no record.). Therefore, adding a CNAME does not solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.