example.com/thread.php?id=100 >>> t100.example.com

Using a single web hosting account to host multiple sites

example.com/thread.php?id=100 >>> t100.example.com

Postby rania » Sun Jun 29, 2008 1:26 pm

hello there,

I am woundring how to rewrite

http://www.example.com/thread.php?id=100

to

http://t100.example.com/
???

after a hard search, I read this topic

http://forum.modrewrite.com/viewtopic.php?t=5744&highlight=rewrite+subdomain+variable

but couldn't find what i'm looking for.

AND I don't have access to httpd.conf to use virtual sub domains ( I belive this is not my problem actually ).

Is it possible to do that using htaccess only ?

to make something clear:

I made some preg_replace to the original output ( which prints the content of allthreads.php file ) and it's links appears like

http://t100.example.com/
http://t101.example.com/
http://t102.example.com/
http://t103.example.com/
http://t104.example.com/

exactly how i want it , BUT when I click any link there , I get 404 error.

I also tried this code in htaccess file :

Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /?id=%1 [QSA,L]


It didn't work too.

I Know I'm a rookie, but you are the way to make me proffissional.

any help will be considered.

God bless you.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby rania » Mon Jun 30, 2008 6:26 am

I'll accept any answer.

just tell , is it possible or not.

i'm losing hope here.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby richardk » Mon Jun 30, 2008 12:33 pm

All the sub domains need to have the same document root as example.com.

In example.com's document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?t([0-9]+)\.example\.com$ [NC]
RewriteRule ^$ /thread.php?id=%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rania » Wed Jul 02, 2008 12:35 pm

it didn't work either brother .

I think there is misunderstood , or I couldn't explain it well .
I don't have any sub domains.

let's say:
the directories and files in my public_html are :

cgi-bin
includes
images
.htaccess
index.php
thread.php

no more folder or files there , OK brother ?

now the file index.php shows all links to the file thread.php as :

http://www.example.com/thread.php?id=100
http://www.example.com/thread.php?id=101
http://www.example.com/thread.php?id=102
http://www.example.com/thread.php?id=103
http://www.example.com/thread.php?id=104

after preg_replace in index.php ,the links shown as :

http://t100.example.com/
http://t101.example.com/
http://t102.example.com/
http://t103.example.com/
http://t104.example.com/

there are no additional folders in public_html ,again .
I won't create any new folders .
I want to visualize these folders ,not creating them actually .
got it brother ?

How to make the variable "id" in thread.php?id=100 act like subdomain ? without creating real folder ?

I belive in you richardk, I know that you have some solutions for me.

and treat me as a " level one begginer " when explaining any of your experiences.

thank you very much for every thing brother.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby richardk » Fri Jul 04, 2008 2:07 pm

I already understand what you want.

What page do you currently see (no mod_rewrite) when you go to a t* sub domain?

When a request to a domain or a sub domain reaches Apache, Apache has to know what directory the request should be sent to. This is the (sub) domain's document root. So, you have to set the sub domain's document root to the directory that the .htaccess file is in or the mod_rewrite will not be processed when you go to the sub domain.

The mod_rewrite part of the solution is what i gave you.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rania » Sat Jul 05, 2008 4:26 pm

richardk wrote:So, you have to set the sub domain's document root to the directory that the .htaccess file is in or the mod_rewrite will not be processed when you go to the sub domain.
.


I hate my self for being so stupid :(

I'm so sorry richardk, I'm not sure how to set the sub domain's document root !

can you tell me about it ?

I think it's not within that code you gave me earlier.

my deeply respect.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby rania » Sat Jul 05, 2008 10:24 pm

it's not me being silly, but I googled for a while, but I could't find the answer about setting subdomain's document root, like i'm the only one who want this to be happen .

how can I know the subdomain's document root when it's virtual ? this driving me crazy.

Did you mean that I suppose to put the .htaccess file toghether with the index.php file in the same directory ( which is /home/example/public_html/ ) ?

=> I did that too , but same problem occured.

Or you ment adding some extra lines under the mod_rewrite code you gave me ?

I am really really really lost.

and your are the only one who can help me.

don't give up with me, I know we can find a way.

i'm not that stupid after all.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby richardk » Mon Jul 07, 2008 1:31 pm

Your virtual sub domains are the same as normal sub domains up until they get to mod_rewrite. All the document root configuration for this is the same.

The setting is either in your hosting control panel, or you will have to edit the httpd.conf (or other configuration file, for example vhost.conf on some configurations) file. You should probably ask your host about it. Or are you running your own server?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rania » Tue Jul 08, 2008 1:55 pm

richardk wrote:Your virtual sub domains are the same as normal sub domains up until they get to mod_rewrite. All the document root configuration for this is the same.

The setting is either in your hosting control panel, or you will have to edit the httpd.conf (or other configuration file, for example vhost.conf on some configurations) file. You should probably ask your host about it. Or are you running your own server?


Ok, maybe you wouldn't belive it, but I bought my Own server just to handle this issue.

Now I have my own server (just three days ago ).

can you show me what exactly changes should i make in httpd.conf or vhost.conf ?

I mean Exactly brother because i'm new for servers stuff as you know.

and If I make those changes, would it affect other domains when i decide to add other domains in the future ?

can't find the best words to thank you.
rania
 
Posts: 7
Joined: Sun Jun 29, 2008 12:46 pm

Postby Minty » Wed Jul 09, 2008 11:09 am

If you have access to some sort of DNS management you want to add an A/AAAA record "*" to your IP address.

If you don't ignore this 'cos I can't help :)
Minty
 
Posts: 5
Joined: Wed May 14, 2008 12:39 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 4 guests

cron