Forum Moderators: phranque
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!
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
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!
.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
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]