2

I am not familiar with .htaccess . I am trying to create .htaccess file which will redirect the any subdomain to portfolio.

For example : bob.example.com ,

which will redirect to the bob portfolio. in background script will be executed following way.

example.com/portfolio.php?id=bob

I have written following .htaccess

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^.*$ http://example.com/portfolio/index.php?id=%1 [R,L]

Issue is , if i use bob.example.com then it actually redirect to example.com/portfolio/index.php?id=bob

if use bob.example.com then must open portfolio direct , instead of redirection

Alright , i managed my self to create it

RewriteRule ^$ portfolio/index.php?id=%1 [NC,L]

Above statement works perfectly ! Thank you !

SSK
  • 285
  • 5
  • 15
  • check this out - http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php?rq=1 – Dinesh May 10 '13 at 09:13
  • They thank you but not so useful – SSK May 10 '13 at 09:23
  • Don't use `.htaccess` for this. Set up a proper vhost configuration and store it in sites-available. http://httpd.apache.org/docs/2.2/vhosts/index.html – Quentin May 10 '13 at 09:25
  • I am using aws , I have added A record in domain control panel. Now i just trying to create virtual domains using .htaccess. – SSK May 10 '13 at 09:27
  • Have you got access to ssh and possibility to create symulinks? – Kasyx May 10 '13 at 09:32
  • yeah i have SSH .. Why there is need of symlink ? – SSK May 10 '13 at 09:36

1 Answers1

0

Try this:

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com [NC]
RewriteRule .* http://domain.com/portfolio/index.php?id=%1 [QSA,R=301,L]

Although I wouldn't recommend you to do this. If you're working with some kind of MVC framework then I'm sure it's routing components can accomplish this for you.

Linus Juhlin
  • 1,175
  • 10
  • 31