Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can access primary domain but not subdomains!!!!

Status
Not open for further replies.

waydown

Programmer
Apr 27, 2009
49
GB
Hi,
My domains are on a virtual server. public_html contains four folders, one for subdomainA, one for subdomainB, a folder called cgi-bin and folderA which contains an ecommerce script. The contents of folderA should really be on my primary domain, i.e. public_html, but the installation for the ecommerce said it should be kept in a separate folder for security reasons or otherwise.

public_html => cgi-bin (folder)
public_html => folderA (folder)
public_html => subdomainA (folder)
public_html => subdomainB (folder)

public_html also contains .htaccess file to redirect to folderA when address of primary domain is typed in.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folderA [NC]
RewriteRule ^(.*)$ /folderA/$1 [L]

If the primary domain address is typed the .htaccess file takes the person to folderA. The trouble with this is if either of the addresses of the subdomains is typed the system looks in folder A for the subdomains and an error is produced.

Not Found
The requested URL /folderA/subdomainA.com/ was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

What I really need is to alter the .htaccess file to something like this:
if(address of primary domain) go to folderA;
else if (address of subdomainA) go to folder subdomainA;
else if (address of subdomainB) go to folder subdomainB;

Would this be possible? If not how can I get around the above problem? All help would be greatly appreciated.
 
Based on what you described I think this is what you are looking for. Let me know if this works for you.

[pre]RewriteEngine On
RewriteCond %{HTTP_HOST} ^(subdomainA\.domain\.com)$ [NC]
RewriteRule ^(.*)$ /folderA/$1 [L]

RewriteCond %{HTTP_HOST} ^(subdomainB\.domain\.com)$ [NC]
RewriteRule ^(.*)$ /folderB/$1 [L]
[/pre]



M. Brooks
 
Hello,
Many thanks for the reply. Sorry for the late response, am involved in a web project so didn't have time to carry out your instructions sooner. I am slightly confused as to where folderB came from:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([highlight #EF2929]subdomainA[/highlight]\.domain\.com)$ [NC]
RewriteRule ^(.*)$ /[highlight #8AE234]folderA[/highlight]/$1 [L]

RewriteCond %{HTTP_HOST} ^([highlight #EF2929]subdomainB[/highlight]\.domain\.com)$ [NC]
RewriteRule ^(.*)$ /[highlight #8AE234]folderB[/highlight]/$1 [L]
I understand that I plug in names for subdomainA and subdomainB but what do I plug in for folderA and folderB. At present folderA contains index.php for my primary domain. I have plugged in subdomainA.com for folderA and subdomainB.com for folderB (which are the folder names given in File Manager) but that is not working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top