Forum Moderators: phranque
We are trying to set-up a simple subdomain for an add-on domain name.
It is to go to a folder within the main domain. So subdomain.secondomain.com is going to [url]www.maindomain.com/afolder[/url]
It doesn't work. Just get a "The page cannot be displayed" error.
We were told by our web host that the .htaccess for the main domain name is stopping the subdomain name from working.
The .htaccess in the root folder is:
AddHandler server-parsed .html
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*jpg$¦.*gif$ [NC]
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!/localhost/ [NC]
RewriteCond %{HTTP_REFERER}!google\. [NC]
RewriteCond %{HTTP_REFERER}!search\?q=cache [NC]
# Edit the line below to match your domain name
RewriteCond %{HTTP_REFERER}!domain\.co\.uk [NC]
What can we do to make this .htaccess file not apply to one of the internal folders?
Many many thanks.
RewriteRule ^afolder/ - [L]
Also, it appears that one or more lines are missing at the bottom of the code you posted. This may cause serious problems, unless you intentionally 'trimmed' the code before posting it.
Jim
I have wasted another two hours on this today, so that must make it a total of about seven hours for something that should take 20 seconds. I hate computers! :(
The web host keep telling me that the problems are to do with .htaccess. However, I have adding
RewriteRule ^foldername/ - [L] and also Rewritecond %{REQUEST_URI}!(^/foldername/.*$) [NC] (which was suggested elsehwere) to the top of the the .htaccess file in the root folder, yet the subdomain still does not work. There is nothing in the .htaccess of the folder, so there is no rhyme or reason why the subdomain does not work if the above commands disable the root .htaccess
The webhost have also told me: "Your .htaccess rule needs to include a rule to allow the subdomain subdomain.domainname.com through, not just the directories".
I would have thought that this would have been done automatically by cpanel, as it should not require modifying the root .htaccess to simply set up a working subdomain.
How would I do this please?
On another note, there is nothing after the above .htaccess code. What is missing please?
Thanks for everything.
[edited by: 1Lit at 12:01 am (utc) on May 9, 2007]
AddHandler server-parsed .html
#
Options +FollowSymLinks
RewriteEngine on
#
# Return 403-Forbidden response for image hotlinking attempts
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !/localhost/ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
# Edit the line below to match your canonical domain name, with literal periods escaped as shown
RewriteCond %{HTTP_REFERER} !(www\.)?example\.co\.uk
RewriteRule \.(jpe?g¦gif¦png)$ - [F]
Since the original code won't work as-is, I suggest you delete everything in the file except for the AddHandler line and see if your subdomain problem changes. If not, then it is not anything in the .htaccess file that is causing the problem. It might still be something missing from the .htaccess file, though.
If the problem doesn't change, then you need to back up and look at the server and the subdomain configuration: How, specifically, did you "add a subdomain?" Did you define an A record in your DNS zone file to point that subdomain to your server? If not, then no computer on earth will know where to go (IP address-wise) when that subdomain is typed into its browser address bar.
You can define a specific subdomain in DNS, or you can (in most cases) define a "wild-card" subdonain, which would be written as "*.domain.com." in the DNS zone file. Note that trailing period, as it is important.
If you've done either of these, and waited for DNS to propagate (4 hours to four days, depending on which ISPs you're accessing the site from), then requests will reach your server. Now the server needs to be told what to do with those requests.
You can define a separate <VirtualHost> for the subdomain, and point that to the location in the filesytstem where you want to store "that site's files." Or you can include the subdomain in the original <VirtualHost> as a ServerAlias. Or, if you have a unique IP address, not shared with other sites, it is possible that the subdomain will already be mapped to the same filespace as you main domain. All of the preceding hostname-to-filesystem mapping is done in httpd.conf, or indirectly through a "Control Panel".
If, however, you don't have access to httpd.conf directly or through a control panel, then it's still possible that the subdomain is pointed to your main domain's filesystem -- You can't tell until the DNS resolves. If this is done, then you may need to add code to your .htaccess file to map the subdomain into a subdirectory of the main domain's filespace. It's easy enough to do, but only confuses things until you figure out the DNS and server configuration -- I cannot cover all of the possibilities and all their logical combinations in one post. :)
As to the mod_rewrite stuff, I assumed it was a snippet of code. Since it wasn't, that means it was badly-broken, and I caution you to not install any mod_rewrite code on your server unless you fully understand it -- and understand all of its implications for your site. Incorrect or inappropriate code in httpd.conf, in conf.d, or in .htaccess can make a very bad mess of your site's operation and destroy search engine ranking as well. So please see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] for a good start on avoiding problems.
Let us know about the DNS configuration, and the result of temporarily cutting back the .htaccess file. We can proceed from there.
Jim