Forum Moderators: phranque

Message Too Old, No Replies

Dynamic subdomains in htaccess

Need to create dynamic subdomains, followed by a parameter

         

meetzah2

12:23 pm on Aug 15, 2011 (gmt 0)

10+ Year Member



Hello.

This is my first post here and I thank you in advance for your help. There are 3 day since I try to make this but I can't see the end of it:

I managed to generate this url aaa.adresa.com which display the content from adresa.com/fisier.php?link=aaa. For that, I used this code:
RewriteCond %{HTTP_HOST} !^www\.adresa\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.adresa\.com [NC]
RewriteCond %{REQUEST_URI} !^/fisier\.php$
RewriteCond %{QUERY_STRING} !^link=.
RewriteRule (.*) /fisier.php?link=%1 [QSA,L]


Further, I need to get this address:
aaa.adresa.com/bbb to display the content of adresa.com/fisier.php?link=aaa&parametru=bbb


Thank you for your help.

lucy24

4:05 pm on Aug 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Looks like you just missed one piece.

RewriteRule (.+) /fisier.php?link=%1&parametru=$1

%1 is the part you captured in the RewriteCond, here "aaa". $1 is the part you captured in the RewriteRule, here "bbb". That's assuming you want to apply the rule to any request, excluding only "fisier.php". This seems a bit risky, but it's your site.

[QSA] means "add to existing query string". If there is no query string before the rewrite, you should leave it out (it does no harm, but isn't needed) and change your final Condition to

RewriteCond %{QUERY_STRING} !.

meaning "contains no text of any kind".

meetzah2

5:45 pm on Aug 15, 2011 (gmt 0)

10+ Year Member



Thank you @lucky24 for your fast reply. A friend from Romania helped me to get this done and I am posting here the solution:

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^www\.adresa\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.adresa\.com [NC]
RewriteCond %{REQUEST_URI} !^/fisier\.php$
RewriteCond %{QUERY_STRING} !^link=.
RewriteRule ^([^/]*)/?$ /fisier.php?link=%1&parametru=$1 [NC,QSA,L]


Have a nice day!