WordPress.org

Support

Support » Multisite » [Resolved] Adding Files to Root Directory with Domain Mapping

[Resolved] Adding Files to Root Directory with Domain Mapping

  • I have a WordPress multi-site network with the plugin WordPress MU Domain Mapping installed and configured. I want to add files (eg. favicon.ico) of same names to the root directory of the mapped domains. Can anyone tell me how to do this?

Viewing 15 replies - 1 through 15 (of 24 total)
  • if it’s just favicon you’re looking for just add/change the <link rel="shortcut icon" href='... in each sites themes header to a custom favicon to that theme (site). Despite Internet Explorers best efforts, favicons don’t need to be in the main public folder.

    If you’re using the same theme, and can’t do it that way.. and still are looking for a directory for each domain that acts like a public root folder for other files than the favicon: so am I so hopefully someone more experienced in domain mapping can contribute,

    It’s not just about favicons. Can we do this by editing the .htaccess file in the blog.dir/(siteid) folder so that all the files and folders that I put in the folder show when I go to mappeddomain1.com/(the files/folders in blogs.dir/(siteid) folder)?

    Don’t screw around with the .htaccess unless you totally understand, on a core level, how the redirections work, and what the ms-files.php does.

    Honestly, how well that works with some thing totally depends on the files and the plugins you’re using. I have a Download plugin that’s smart enough to put things in blogs.dir/#/files/downloads, but it’s REALLY dependent of it the plugin CORRECTLY utilizes filters (i.e. upload_dir() ) and not silly hard coding of wp-content/uploads (yes, many people do that).

    Now. IN THEORY. The way your .htaccess is written already takes it into account. Look at the line
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    That’s from the subfolder install, and says ‘take files/whatever’ and parse it to wp-includes/ms-files.php?file=whatever – So that SHOULD already work.

    And having tested it, http://halfelf.org/files/test.txt works 🙂 The file is at `/wp-content/blogs.dir/#/files/test.txt’

    So as far as THAT goes, works out of the box.

    The catch? My files folder is locked down so PHP can upload to it, but that’s just my set up.

    But I want to add files in the root directory. For eg. http://halfelf.org/test.txt, not http://halfelf.org/files/test.txt

    And this is why I pointed you to a plugin.

    You CAN, but it involves knowing REAL well how .htaccess works, and being familiar with RewriteCond.

    Example.

    RewriteCond %{HTTP_HOST} !^example\.com
    RewriteRule test.txt http://otherplace.com/404page

    But that’s actually pretty complicated when you get into a ton of files, and it’s not efficient (nor is it easy).

    Read http://perishablepress.com/creating-the-ultimate-htaccess-anti-hotlinking-strategy/ for how the ulitmate hotlnk protection works. That’s what I’d TRY to fork if I had to. But then again, I just use a favicon plugin or a filter in my functions for the themes.

    This is an example (untested) function:

    function add_theme_favicon() {
    $uploads = wp_upload_dir();
    $favicon = $uploads['basedir'] .  '/favicon.ico';
      if (file_exists($favicon)) {
        echo '<link rel="shortcut icon" href="$favicon" >';
      }
    }
    add_action('wp_head', 'add_theme_favicon');

    Put the favicon in the /files/ folder for that site, and it’ll check. If the file is there, show the favicon. Else, don’t show anything 🙂

    The whole reason this is a hassle is that you’re expected to use WordPress to manage things, not a home brew.

    Thanks. Does somebody know a simpler/automated method?

    Given that the answer is ‘no, there isn’t a simpler method’ let’s take a step back 🙂

    1) WHAT files, specifically, are you trying to put in there?
    2) Can they be the same for ALL domains?
    3) Do they HAVE to be in the root or do you just really want them to be?

    1) Google verification files (Don’t tell me to add meta tags), favicon etc.
    2) No
    3) They have to be in the root.

    The answer is STILL plugins.

    Favicon: http://wordpress.org/extend/plugins/shockingly-simple-favicon/ (or the function I gave you)

    Google Verification: http://wordpress.org/extend/plugins/wordpress-seo/ And YES it uses meta (why are you adverse to meta? That’s what it’s there for. Works like a champ).

    Man, you’re making this WAY harder than you need to. What’s wrong with the plugins?

    They make the server slow.

    Also, I have to add verification of Google Apps and Webmaster Tools.

    Do you really think that these plugins are going to make your site slower than the amount of function application you’ll need to use in order to replicate exactly what those plugins do?

    Answer: No, they won’t slow your site any more than a homebrew you can come up with. Suck it up, use the right tool for the job.

    I also need to add some other files for which no plugins are there.

    Repeating since you missed this: WHAT files, specifically, are you trying to put in there?

    List ’em. Seriously. We can’t help if we don’t know.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘[Resolved] Adding Files to Root Directory with Domain Mapping’ is closed to new replies.
Skip to toolbar