← Desenvolvimento

É possível usar "criar" subdomínios com .htaccess ?

Lida 7381 vezes

Offline

sapovideo 
Membro
Mensagens 295 Gostos 0
Troféus totais: 25
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts

Viva,

Gostaria de saber se é possível criar tipo subdomínios como o hi5.com tem.... meunome.hi5.com dinamicamente usando regras no .htaccess.... ou alguma forma de ter subdominios dinamicamente ....
Offline

Henrique Mouta 
Equipa
Mensagens 1189 Gostos 3
Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3

tens de PHP'ar e editar no httpd.conf
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Virtual hosts.
Offline

skin 
Membro
Mensagens 200 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Avatar Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Sim, é possível e nada é bem mais simples do que como o cenourinha e o vaurdan disseram. Se souberes usar as configurações para escrever um bom .htaccess consegues isso.
Por exemplo:

Código: [Seleccione]
Options +FollowSymLinks
 
RewriteEngine On

# abc.joaopedropereira.com --> /subs/abc/
 
RewriteCond %{HTTP_HOST} !^(www\.)?joaopedropereira\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.joaopedropereira\.com$ [NC]
RewriteCond %1:::%{REQUEST_URI} !^(.+):::/subs/\1(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subs/%1/ -d
RewriteRule ^(.*)$ /subs/%1/$1 [QSA,L]