redirect subdomain to a php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mostafa.fayyaz
Forum Newbie
Posts: 5
Joined: Mon Jul 27, 2009 12:08 pm

redirect subdomain to a php file

Post by mostafa.fayyaz »

hello !
i want to redirect all subdomains to show.php.
for example :
test.mydomain.info
to
show.php?url=test

i want to use .htaccess file . but it does't work
plase help me
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: redirect subdomain to a php file

Post by jackpf »

I've never done this myself, so I'm not entirely sure....but this may be worth a look.
mostafa.fayyaz
Forum Newbie
Posts: 5
Joined: Mon Jul 27, 2009 12:08 pm

Re: redirect subdomain to a php file

Post by mostafa.fayyaz »

jackpf wrote:I've never done this myself, so I'm not entirely sure....but this may be worth a look.
i'm sure . i saw this code.
but i forget url
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: redirect subdomain to a php file

Post by jackpf »

Does it work?
mostafa.fayyaz
Forum Newbie
Posts: 5
Joined: Mon Jul 27, 2009 12:08 pm

Re: redirect subdomain to a php file

Post by mostafa.fayyaz »

this is a example :

Code: Select all

 
Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9]+)/?(.*)$ go.php?s=$1&file=$2 [L,QSA]
 
but i don't know why this code doesn't work
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: redirect subdomain to a php file

Post by jackpf »

I have to admit I'm not sure. As I said, I've never actually done this...I just thought that link would be useful.

Sorry I can't be of more help...I'll have to leave this to someone else :( Sorry

All I can suggest is to search google for "subdomain rewrite" or something similiar...
User avatar
swhistlesoft
Forum Newbie
Posts: 9
Joined: Fri Aug 14, 2009 10:53 pm
Location: Ontario

Re: redirect subdomain to a php file

Post by swhistlesoft »

This might be what you are looking for.

# if requested subdomain is not "www"
rewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
# and we have not already rewritten this request to the subdomain's subfolder
rewriteCond %{THE_REQUEST} !/folder/.
# extract requested subdomain to %2
rewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
# rewrite the request to the subdomain's subfolder
rewriteRule (.*) /folder/%2/$1 [L]
Post Reply