WordPress.org

Forums

[resolved] Adding Files to Root Directory with Domain Mapping (25 posts)

  1. KB24x7
    Member
    Posted 2 years ago #

    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?

  2. davidsword
    Member
    Posted 2 years ago #

    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,

  3. KB24x7
    Member
    Posted 2 years ago #

    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)?

  4. 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.

  5. KB24x7
    Member
    Posted 2 years ago #

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

  6. 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.

  7. KB24x7
    Member
    Posted 2 years ago #

    Thanks. Does somebody know a simpler/automated method?

  8. 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?

  9. KB24x7
    Member
    Posted 2 years ago #

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

  10. 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?

  11. KB24x7
    Member
    Posted 2 years ago #

    They make the server slow.

  12. KB24x7
    Member
    Posted 2 years ago #

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

  13. 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.

  14. KB24x7
    Member
    Posted 2 years ago #

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

  15. 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.

  16. KB24x7
    Member
    Posted 2 years ago #

    @lpstenu Why are you so determined to use plugins? I need to add Google Apps verification (no plugin for that), Bing site verification and other things. Also if in the case of an emergency to prove that the domain is mine, what should I do? Make my own plugin?

    @Everyone If anyone knows how to add files in the root directory for a custom domain, please tell me.

  17. Because that's how you correctly do these things for WordPress and Multisite.

    Why are you so determined to reinvent the wheel?

    I need to add Google Apps verification (no plugin for that), Bing site verification and other things.

    http://wordpress.org/extend/plugins/wordpress-seo/ does ALL OF THAT.

    So does http://wordpress.org/extend/plugins/webmaster-tools-verification/ (which ONLY does verification, if you're that worried about speed).

    If you know how to code it on your own, go ahead and do it. But you cannot add in files to the root of PARKED DOMAINS and have them be one domain only, unless you want to have a highly complex .htaccess file. This is nothing to do with WordPress. This is how parked domains work in general. You park one domain on another and everything runs from the same source.

    WordPress already is doing the heavy lifting you would need to recreate via .htaccess. Example:

    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule google-verification.txt http://example.com/example-google.txt
    
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule bing-verification.txt http://example.com/example-bing.txt

    Over. And over. And over. For every domain, every file, etc etc and so on. And the more weird files you add, the more work you have to do.

    There's nothing wrong with using the appropriate plugin for the job. That's what you're supposed to do. It's part and parcel with how and why WP was coded the way it was.

  18. KB24x7
    Member
    Posted 2 years ago #

    Thanks for your help.

  19. Adding -- Google apps you don't need to do anything on your site, had you bothered to read their documentation.

    You can use this option if are able to sign in to your domain registrar or hosting provider and add a new DNS record.
    Instructions:
    This enables us to provide more specific instructions.
    A TXT record is an entry within the Domain Name System (DNS) that provides supplemental information about your domain. You can create a TXT record that proves to Google that you own the domain.

    Boom.

    Done.

    (Which is how WordPress.com does it, by the way)

  20. KB24x7
    Member
    Posted 2 years ago #

    Can you link me to it?

  21. CChuang
    Member
    Posted 2 years ago #

    I have the same situation: I have a WordPress multi-site network with the plugin WordPress MU Domain Mapping installed and configured. However I would like to add a new directory to the root. In my case, I cannot just create a new folder in the root directory via FTP (because that would just be too easy ... long story... short story... red tape!)

    Can I do that through a plugin and if so, which do you recommend.

    The file I have to add is from a 3rd party and they require a very specific path in order for the file to work the way it is intended.

    Any help?

  22. CChuang - A little different, and generally you should make your own topic (everyone's solutions are a little different, and dude, I hate red tape too! Ugh!)

    If the files need to be downloaded, I'd use http://wordpress.org/extend/plugins/download-monitor/

    If they just need to be 'seen' I'd edit my .htaccess ... Put the files in /wp-content/blogs.dir/#/specialfolder/ and then something like this...

    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule /specialfolder/(.*)$ http://example.com/wp-content/blogs.dir/#/specialfolder/$1 [L]
  23. gmorales
    Member
    Posted 2 years ago #

    I have a "filefolder" in wp-content with plenty of PDFs in it. With multisites, I clone sub-sites. They look at the files with this link: wp-content/blog.dir/#/files/filefolder/file.pdf.
    I want to modify this link to wp-content/filefolder/file.pdf

    Is this correct:
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule /filefolder/(.*)$ http://example.com/wp-content/blogs.dir/#/filefolder/$1 [L]

Topic Closed

This topic has been closed to new replies.

About this Topic