0

I don't have experience in htaccess and failed to find solution for that.

Simply, i want to make

something1.domain.com to open www.domain.com/something1.php
something2.domain.com to open www.domain.com/something2.php

& www.domain.com open www.domain.com/index.php

Thanks

Fady
  • 23
  • 2
  • possible duplicate of [.htaccess rewrite subdomain to directory](http://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory) – Taylan Aydinli Dec 02 '13 at 06:24

2 Answers2

0

Place this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.domain\.com$ [NC]
RewriteRule ^/?$ http://www.domain.com/%1.php [L,R=302]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Here is one way of doing it -

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www)\.
RewriteCond %{HTTP_HOST} (.+)\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/%1.php [L]

I am assuming you have allowed overrides using AllowOverride directive in apache configuration. You have to enable mod_rewrite if the redirect has to be transparent. If you do not want that then remove the 'L' flag. The L flag prevents further processing of rules and immediately applies the rule that matched.

Community
  • 1
  • 1
Vikram Rao
  • 514
  • 3
  • 16
  • I found that AllowOverride is not enabled, i am on shared hosting, and i don't know how i can enable it. Any help ? – Fady Dec 02 '13 at 14:50
  • How did you find out the AllowOverride is not enabled? Usually in shared hosting you have to contact support to get any changes in the Apache configuration. – Vikram Rao Dec 02 '13 at 15:05
  • I contacted them, they replied that "The allowoverride is not needed, nor is it permitted" .... is there alternative solution ? – Fady Dec 03 '13 at 01:08
  • Well then you should be able to configure sub-domains to folders in c-panel and then have something*.php in the domain specific folders but as index.php. – Vikram Rao Dec 03 '13 at 01:52