Question

I have a .ne.ro domain (registered in Romania) where visitors can enter with or without 'www':

http://mydomain.ne.ro
http://www.mydomain.ne.ro

I want to redirect http://123.mydomain.ne.ro to http://mydomain.ne.ro?id=123. If visitor enter with 'www|mail|ftp' must be treated as non parameter (obviously).

I tried htaccess subdomain redirct with last url parameter but didn't work.

Current code:

# edited on 05/April/2011 as suggested:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$
RewriteRule ^$ /index.php?id=%1 [R,L]


Hosted on a hostgator's business plan (linux) and registered at nic.ro, just if asking.

Was it helpful?

Solution

After many suggested code (thanks supersuphot) and a lot of research finally I found an answer.

First I added the subdomain * under mydomain.ne.ro, pointed to domain folder/path:

Create subdomain *, hostgator shared account

Then I uploaded .htaccess file with the next code:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain.ne.ro
RewriteCond %{HTTP_HOST} ^(.+).mydomain.ne.ro
RewriteRule ^([^/]*)$ http://mydomain.ne.ro/?id=%1 [P,L]

this works too:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$
RewriteRule ^$ /index.php?id=%1 [P,L]

The most important thing is the P instead R at last line, to keep original subdomain. Check this answer to a related question.

OTHER TIPS

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$
RewriteRule ^$ http://mydomain.ne.ro?id=%1 [R,L]

Wow quantme !

I'm searching that code since two days , eh finally ...

Your first code is perfect for me

RewriteRule ^([^/]*)$ http://mydomain.ne.ro/?id=%1 [P,L]

Also You can change with this(for Uppercase or Lowercase letters )

RewriteRule ^(.*)$ http://mydomain.ne.ro/?id=%1 [P,L]

Many Thanks quantme

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top