Forum Moderators: phranque

Message Too Old, No Replies

.htaccess in subdomain not working in a Godaddy hosting

Replicate site in subdomain, .htaccess issues

         

mousemedia

7:12 pm on Sep 17, 2008 (gmt 0)

10+ Year Member



Hello friends, I'm relatively new at apache and .htaccess. I have a site in the the main 'www' root. Our php app works perfectly, customers login by entering their unique "ID" so, for instance, www.mysite.com/welcome.php becomes www.mysite.com/9999 for them to access their unique login page.

This is done with an .htaccess on the root:
DirectoryIndex welcome.php
RewriteEngine on
RewriteRule ^([0-9]+)/?$ welcome.php?store_id=$1 [L]

Everything works when I copied the site to a subdomain, admin, new database, etc, but what's not working is the .htaccess file. If I enter subdomain.mysite.com/9999 I get "Page not found error". I called GoDaddy and they said that .htaccess don't work in subdomains, that the .htaccesss in the root should specify what needs to happen in subdomains.

Any insight on how I make this work? Do I need to tweak the .htaccess in the subdomain, or adjust the one in the root?

Please help! Thanks!

jdMorgan

10:52 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are the subdomains present as subdirectories in your main domain's file space? Is there code in your main .htaccess file that 'points' the subdomains to these subdirectories?

If yes to both questions, then add the subdirectory path to both the RewriteRule pattern, and add a RewriteCond exclusion to prevent rewriting to /subdomain if the REQUEST_URI variable already starts with "/subdomain" -- Otherwise, you'd get an infinite loop.

If the answer to either question is "no," then get GD back on the phone, and tell them you got a wrong answer the first time...

Jim

mousemedia

1:45 am on Sep 19, 2008 (gmt 0)

10+ Year Member



Hi Jim:

Thanks for the reply. Yes, the godaddy hosting creates a directory on the root level for the subdomain. And no, there is no code in the main .htaccess file that 'points' the subdomains to these subdirectories? I guess that's the code I'm looking for.

The .htaccess on the main directory has simply this code:

DirectoryIndex welcome.php
RewriteEngine on
RewriteRule ^([0-9]+)/?$ welcome.php?store_id=$1 [L]

Thanks for any additional help!

jdMorgan

2:16 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's be clear on this, since it's critical...

In your main directory, you have the .htaccess file, and a subdirectory that corresponds to your new subdomain, correct?

Jim

mousemedia

3:15 am on Sep 19, 2008 (gmt 0)

10+ Year Member



Yes that is correct.

jdMorgan

3:48 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, then try this in example.com/subdomain-subdirectory/.htaccess

DirectoryIndex /subdomain-subdirectory/welcome.php
RewriteEngine on
RewriteRule ^([0-9]+)/?$ /subdomain-subdirectory/welcome.php?store_id=$1 [L]

Jim

mousemedia

2:19 pm on Sep 19, 2008 (gmt 0)

10+ Year Member



Thanks for the reply.
I tried your suggestion above, and still get a Page not found error. Keep in mind that the .htaccess file also has to work for not only for the subdomain but for the same site in the 'www" main directory.

jdMorgan

2:31 pm on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nope, you can't do that...

.htaccess files are only processed if they are in the directory path traversed by the server when accessing the directory associated with a URL. If the subdomain files are stored in a subdirectory below your top domain, and the server configuration points subdomain requests directly to that subdirectory (rather than using code in the .htaccess file in the top domain's filespace to pass requests down to the subdomain's subdirectory, as mentioned above), then the .htaccess file for the top-level domain will never be executed for requests to the subdomain, and vice-versa.

I'd suggest replacing your rewrite with a simple redirect if you want to pursue hosting with this company. In this way, you eliminate any complications with the directory paths in the substitution URL/filepath, the cart script, etc., and success (if you have it) will be immediately obvious. Something like "RewriteRule ^foo\.html$ [google.com...] [R=302,L]" makes for a good test rule. If you request "foo.html" from you subdomain and land at google, then you know it worked. Divide and conquer the problem, as it were...

Also, look at your server error log when you get any error -- The information there is often critical to solving problems. In the case of "page not found," you should see the filepath from which the server attempted to serve the failed URL request. By comparing that filepath to the one you expect, the problem is often revealed.

Jim

mousemedia

2:37 pm on Sep 19, 2008 (gmt 0)

10+ Year Member



Awesome feedback! Will try it out and let you know.

Thanks again!

mousemedia

8:57 pm on Sep 22, 2008 (gmt 0)

10+ Year Member



OK, change in approach. I tried everything above and to no avail. But I switched my strategy. Since I have this .htaccess limitation with the hosting company, I moved the replicated www.mysite.com to www.mysite.com/canada , so a replicated site no longer resides in subdomain.mysite.com. Both sites work fine in the root and subdirectory.

I modified the .htaccess so the anyone landing on subdomain.mysite.com re-directs to www.mysite.com/canada. Here is my new .htaccess file:
DirectoryIndex welcome.php
RewriteEngine on
RewriteRule ^([0-9]+)/?$ welcome.php?store_id=$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.example.com$
RewriteRule ^(.*)$ http://www.example.com/canada/ [R=301,L]

But now my client wants to mask the the http://www.example.com/canada/ with the subdomain. So for instance http://www.example.com/canada/anything.php would read in the browser bar http://subdomain.example.com/anything.php

Is this possible?

Thanks again!

[edited by: jdMorgan at 3:01 am (utc) on Sep. 23, 2008]
[edit reason] Please use example.com [/edit]