Subdomain redirection at . htaccess

Asked

Viewed 1,066 times

1

I am trying to do a subdomain redirect on . htaccess as follows:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{HTTP_HOST} !^testephp\.com\.br
RewriteCond %{HTTP_HOST} ([^\.]+)\.testephp\.com\.br$ [NC]
RewriteRule ^/?$ http://testephp.com.br/index2.php [L,QSA]

if I enter the url http://testephp.com.br works right, everything ok, however, when typing something similar to http://xpto.testephp.com.br I am not redirected to anywhere, only get error: ERR_NAME_NOT_RESOLVED.

I’m using shaman on my local machine.

1 answer

1

This setting you should do in the virtual host configuration of your domain:

ServerName       testephp.com.br
ServerAlias xpto.testephp.com.br

Also, don’t forget to edit your file hosts to understand the requests to both domains as requests to 127.0.0.1.

  • My vhost is like this: <VirtualHost *:80>&#xA; ServerAdmin [email protected]&#xA; DocumentRoot "D:/xampp/htdocs/testephp"&#xA; ServerName testephp.com.br&#xA; ServerAlias *.testephp.com.br&#xA; <directory "D:/xampp/htdocs/testephp">&#xA; AllowOverride All&#xA; Order Allow,Deny&#xA; Allow from all&#xA; Require all granted&#xA; </directory>&#xA;</VirtualHost>

  • As far as I know, it is not possible to use a wildcard on ServerAlias. You must discriminate between the subdomains one by one.

  • I understand, but how do I then have dynamic subdomains?

  • I searched and it seems that it is possible. Check out this tutorial: http://blog.calcatraz.com/wildcard-subdomains-in-apache-1422

  • Thanks friend but I could not. I will continue my research and if I get something put here to help others who have the same problem.

Browser other questions tagged

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