Forum Moderators: phranque

Message Too Old, No Replies

How is htaccess used with subdomains?

best to place an htaccess file in each subdomain?

         

zollerwagner

9:58 pm on Mar 28, 2005 (gmt 0)

10+ Year Member



For a multilingual site, I have the different language versions in subdomains of the same domain name.

The site's .htaccess file:

  • sets up parsing of html pages as php
  • assigns error documents for specific error numbers
  • disallows indexes, allows includes and following symbolic links
  • forces use of canonical URLs with rewrite
  • uses rewrite to block hotlinking
  • sets up permanent redirects for any pages that are renamed or no longer in use

    I have three questions.
    1. Is it best to use a different .htaccess file for each subdomain?

    2. I tried placing just one .htaccess in the www. root. The html pages did get processed as php, even in the subdomains, but other functions didn't seem to work, particularly the hotlinking. (Images in the subdomains were blocked when they should have been visible.)
    Is that because when a page is requested from the subdomain, the server doesn't go to the www root first? Or is this possible and I just did something wrong?

    3. Am I right in assuming that I don't can't force a canonical URL in the subdomain? Trying that put the server in a loop. Actually, it looks like it's not needed because you can't type a non-canonical URL that goes to the subdomain, can you?

    Thanks!

  • moltar

    10:13 pm on Mar 28, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Instead of duplicating the same file across your subdomains, you can create links if you are on *nix based system.

    ln -s target linkname
    - creates a symbolic link, like a shortcut to the target directory or filename.
    ln target linkname
    - creates the default hard link. Deleting this will delete the targetted file or directory.

    zollerwagner

    1:34 am on Mar 29, 2005 (gmt 0)

    10+ Year Member



    That's an interesting idea. Is the main advantage in having just one file to maintain?

    I supposed I'd have to have command line access to the system to use a soft link.

    Would I add the symbolic link in the directory in which I want to make that file available?

    To force the canonical URLs would I just add something like this below?

    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST}!^(www\.¦en\.¦ast\.¦fr\.)mydomain\.com
    RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]

    That assumes a root (www) and three different subdomains (en, ast, and fr).

    zollerwagner

    2:05 am on Mar 29, 2005 (gmt 0)

    10+ Year Member



    Hmm. Now that I've fixed a problem with referring to the multiple subdomains (one\.¦two\.¦three\.) I'm not seeing any problems.

    Do you only need one htaccess file even if you have subdomains?

    jdMorgan

    6:44 am on Mar 29, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Subdomains don't mean anything special to .htaccess. By the time .htaccess is run, you are accessing files, not URLs. So, I suspect you're really asking "How is .htaccess used with subdomains mapped into subdirectories?" and the answer is, "It's used just like it is in any other subdirectory." Maybe that will clear things up a bit... I hope so, anyway. :)

    Jim

    zollerwagner

    8:09 am on Mar 29, 2005 (gmt 0)

    10+ Year Member



    That makes sense, Jim. In fact, as you say, if you look at the file structure in the site, the subdomains are just folders in the root directory. So I suppose that's why the one .htaccess file in the root works just like it would with folders in a site that doesn't have subdomains. Well, that makes things a lot easier. Thanks!