WordPress.org

Ready to get started?Download WordPress

Forums

Infinite redirect / Conditional .htaccess (31 posts)

  1. everwill
    Member
    Posted 3 years ago #

    My MU has multiple sites with very specific info in each site. However, there are certain over-arching zones of interest that apply across multiple blogs. I'd like to avoid duplicate content on multiple sites but I want the easiest possible user experience. So, what I've decided would be best is to use .htaccess to route certain specific directories to the parent site. That way, if you're go to:

    http://site.com/topic-x
    http://site1.com/topic-x
    http://site2.com/topic-x
    http://site3.com/topic-x

    You'll end up at
    http://target-site.com/topic-x

    So what I found works is that I drop this into the htaccess of a given directory:

    RewriteEngine on
    RewriteRule ^(.*)$ http://target-site.com/topic-x/$1 [R=301,L]

    This works great for Topic-x.

    Here's my problem: topic-y is actually a dynamic executable that has redirect built-into the code. That means that the code at target-site.com/topic-y automatically directs to http://target-site.com/topic-y which is where my .htaccess redirects to target-site.com and so on forever.

    In this case, re-writing the executable is not an option. And, because I'm using MU whatever I drop into that directory applies to every site on the host.

    I think what I need is a conditional .htaccess statement but writing that conditional htaccess is beyond my present experience.

    Help?

  2. everwill
    Member
    Posted 3 years ago #

    Maybe I put this in the wrong forum?

  3. No, you're just impatient :)

    1) Don't bump (it's against forum guidlines)
    2) Be patient, it's the holidays for the vast majority of people (and the rest of us are at work)

    Okay. Firstly, it's MultiSite, not MU. If you say MU we're gonna think you're on old 2.9.2 MU ;) Trust me, it does matter.

    Your rewrite rule will redirect EVERYONE to topic-x ... wouldn't you want this?
    RewriteRule ^topic-x(.*)$ http://target-site.com/topic-x$1 [R=301,L]

    Though if target-site is also on the same account on the server (and multisite install), that could cause other fun redirect loops.

    You may need to do something like this:

    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?(site1|site2|site3)\.com
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^topic-x(.*)$ http://target-site.com/topic-x$1 [R=301,NC,L]

    That's untested, though.

  4. everwill
    Member
    Posted 3 years ago #

    Thanks for the reply and sorry for the bump.

    What would be most helpful if you have it is a link to a tutorial or syntax reference for .htaccess. Much as I'd love for you to write this for me (and you probably will before all is said and done), I'm just learning how to use .htaccess redirects so I might need to tweak this.

    What might not be clear above is that the proposed redirect was placed in the .htaccess for the directory /topic-x/ and in that way applied to "everything" but everything in the /topic-x/ directory.

    I'll doctor and test the code and may come back crying for more, but let me just make sure I'm clear here:

    # I think this is how I add remarks and therefore:
    # Turn on rewrites.
    RewriteEngine on
    
    #This means re-write everything?
    RewriteBase /
    
    #This sets up the conditions of the rewrite. If I needed to add .info #or .biz or whatever, I would use (site1.com|site2.biz|site3.org)
    #and remove \.com
    RewriteCond %{HTTP_HOST} ^(www\.)?(site1|site2|site3)\.com
    
    #I have no idea what this does.
    RewriteCond %{REQUEST_FILENAME} !-d
    
    #Or this ...
    RewriteCond %{REQUEST_FILENAME} !-f
    
    #Rather than being put in the topic-x directory, this assumes that the #code is in the root, so ^topic-x(.*) means everything on every site #with topic-x in the URL goes to the target-site with the same string #following. I'm not sure what R=301,NC,L means.
    RewriteRule ^topic-x(.*)$ http://target-site.com/topic-x$1 [R=301,NC,L]
  5. everwill
    Member
    Posted 3 years ago #

    Oops ... I just realized I made a mess in the code above, but I don't know how to edit my post. :^(

    This is not a bump, just an apology! ;^)

  6. It's okay :) No worries!

    RewriteBase / sets the BASE location of where your rewrites begin from. For example, if WordPress was in another folder, then the base would be /foldername :)

    You got RewriteCond pretty right :) The next two are checking for directories (d) and files (f). Really I think you could merge them.

    R=301,NC,L is a rewrite condition, that says 'Treat these as a 301 HTTP call.

    http://corz.org/serv/tricks/htaccess.php and http://corz.org/serv/tricks/htaccess2.php are good resources.

    I also get a lot of my tricks from http://perishablepress.com/ who covers a LOT of topics.

  7. everwill
    Member
    Posted 3 years ago #

    So here's what I came up with:

    # Turn on rewrites.
    RewriteEngine on
    
    RewriteBase /
    #I'll add the others later. Let's get one working.
    RewriteCond %{HTTP_HOST} ^(www\.)?(condo-alexandria|site2|site3)\.com
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^topic-x(.*)$ http://nesbitt-realty.com/idx/$1 [R=301,NC,L]

    The problem is when I uploaded it I am sent to this location:

    http://condo-alexandria.com/idx/mls-fx7500861-1610_6th_pl_mclean_va_22101

    Where upon it tells me "the webpage cannot be found" as in browser / URL error rather than as in 404 error. Of course as soon as I rename .htaccess to fjdkal.htaccess, the page loads ... but not at the target URL.

  8. Do you still have topic-x in there or is it idx? Let's try the straightforward...

    # Turn on rewrites.
    RewriteEngine on
    
    RewriteBase /
    #I'll add the others later. Let's get one working.
    RewriteCond %{HTTP_HOST} ^(www\.)?condo-alexandria\.com
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^idx(.*)$ http://nesbitt-realty.com/idx$1 [R=301,NC,L]

    BTW, the lack of a / in http://nesbitt-realty.com/idx$1 is intentional :) Since the search is for idx(.*) WITHOUT a trailing /, you don't need to add it in.

  9. everwill
    Member
    Posted 3 years ago #

    Actually it's nesbittrealty.com but no matter, I can handle that kind of edit. ;^)

    I think I'm much closer. I'm getting this error now:

    <strong>Not Found</strong>
    
    The requested URL /idx/mls-fx7500640-7201_churchill_rd_mclean_va_22101 was not found on this server.
    
    <hr>
    
    <em>Apache/2.2.14 (Unix) Server at condo-alexandria.com Port XX</em>

    (Where XX is my port number.)Here's what's curious though ...

    After it gave me the error, I tried this one instead:

    # Turn on rewrites.
    RewriteEngine on
    
    RewriteBase /
    #I'll add the others later. Let's get one working.
    RewriteCond %{HTTP_HOST} ^(www\.)?nesbittrealty\.com
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^idx(.*)$ http://condo-alexandria.com/idx$1 [R=301,NC,L]

    In other words I swapped the URLs to see what would happen. Browsed to http://condo-alexandria.com/idx/mls-fx7500562-8220_crestwood_heights_dr_704_mclean_va_22102 and at the same URL with the following error:

    <strong>Not Found
    </strong>
    The requested URL /idx/mls-fx7500562-8220_crestwood_heights_dr_704_mclean_va_22102 was not found on this server.
    <hr>
    <em>Apache/2.2.14 (Unix) Server at condo-alexandria.com Port XX</em>

    I don't know what I'd do without the kindness of strangers, and I feel bad for imposing upon you as much as I have already. I'll start paging through the resources you referenced.

  10. everwill
    Member
    Posted 3 years ago #

    The critical information that I withheld that I think might be pertinent is this:

    Everything in the /idx/ folder bounces off someone else's code and database and builds on my site. In other words, I have no code, DB or anything else at /idx/ and this is why I cannot easily modify that code. No doubt there is a redirect built into that pile of spaghetti that shoots it back to my box and that is probably conflicting with / trying to over-write what I'm trying to do.

  11. Hmmm. Whatever generates the destination shouldn't matter.

    The goal is 'Anyone who goes to http://condo-alexandria.com/idx/mls-fx7500562-8220_crestwood_heights_dr_704_mclean_va_22102 should be redirected to http://nesbittrealty.com/idx/mls-fx7500562-8220_crestwood_heights_dr_704_mclean_va_22102 instead' correct?

    This error is interesting.

    Not Found

    The requested URL /idx/mls-fx7500640-7201_churchill_rd_mclean_va_22101 was not found on this server.

    <hr>

    Apache/2.2.14 (Unix) Server at condo-alexandria.com Port XX

    See how it's still pointing to condo-alexadria.com? Are they both domains handled by the MultiSite with condo-alexadria as the master domain, or are they something else?

  12. everwill
    Member
    Posted 3 years ago #

    You have described the goal accurately, but to be crystal clear the goal is to have anything that goes to http://condo-alexandria.com/idx/ANYTHING go to http://nesbittrealty/idx/THE SAME THING.

    Both are handled by Multisite with condo-alexandria as the Master Domain.

    I have a Plesk panel if that adds or subtracts from the confusion.

  13. Yeah, we're on the same page with the goal :) Just making sure.

    Okay. Master domain is condo, child domain is nesbitt.

    Let's try a pared down, less flexible version for a moment.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.condo-alexandria.com$[OR]
    RewriteCond %{HTTP_HOST} ^condo-alexandria.com$
    RewriteRule ^idx/(.*)$ http://nesbittrealty.com/idx/$1 [R=301,NC,L]

    (all I know about Plesk is that it's wildcard subdomain setups drive a person to drink)

  14. the goal is to have anything that goes to http://condo-alexandria.com/idx/ANYTHING go to http://nesbittrealty/idx/THE SAME THING.

    Then why not map both domains to that blog (if it's a sub site)?

    the domain mapping plugin lets you do that.

  15. everwill
    Member
    Posted 3 years ago #

    Andrea,

    Unless I'm misunderstanding something, I can't seem to map more than one domain to my parent domain. I can map multiple domains to any other domain but not that one. I can forward a domain to my parent domain but I can't alias.

    That said, I just need that /idx/ folder to redirect because if I can get it to work, I'll do that will 50+ other domains.

    Master Half-Elf,

    I tried the code a moment ago and it was the same error (not found). Here's what I think is happening. The .htaccess is redirecting the request immediately. Normally a request to that directory would bounce off a data provider's server and back to me, but in this case the file is not found because the file doesn't exist as the redirect is happening before the executable. In other words, I think the code is doing exactly what you expect it to do, but that's not the solution to this environment.

    Because the file doesn't exist and never existed on my server, I'm starting to believe that this method will never work to accomplish my goal. Hopefully these snippets of code will help the next guy looking for a redirect snippet in the forums.

    Andrea,

    Do you have a specific plugin you are recommending? I want to see if I have it installed already to make sure I'm not missing something.

    I VERY much appreciate the help of both of you ... even if I don't have a solution and might have an unsolvable problem.

  16. I can't seem to map more than one domain to my parent domain.

    Ah, gotcha. Actually, you can't map *any* domain to the main domain...

    If you're really looking for multiple domains to resolve to the same blog... then maybe multisite is not what you're looking for.

  17. everwill
    Member
    Posted 3 years ago #

    I need multi-site because I have more than 100 different domains. The problem (as I stated in my OP) is that while each domain has certain very specific information to that domain, some information is general to all domains and I don't want to duplicate the content in all of those domains. Rather I want one specific folder to in all of those domains to resolve to the main domain.

    As a side note I wish I'd known before I configured that you can't map more than one domain to the main domain. That sort of sucks.

  18. everwill
    Member
    Posted 3 years ago #

    Rather I want one specific folder to in all of those domains to resolve to the main domain.

    I mean to say: Rather I want one specific folder to in all of those domains to resolve to a specific folder on one of these domains.

  19. some information is general to all domains and I don't want to duplicate the content in all of those domains.

    I thought I addressed this earlier, but...

    duplicate content only pertains to content on the *same* domain. If it didn't, then there wouldn't be post scrapers. ;)

    If you had subfolder blogs with the same content, Google would give you a duplicate content warning.

    If they are subdomain blog, Google will *not* give duplicate content warning.

    Same as if they are full domains.

  20. everwill
    Member
    Posted 3 years ago #

    I supposed I could just flesh out all these with the same content ...

    Google was a concern, but I also wanted to make it easier for the user to see and understand the structure ...

  21. everwill
    Member
    Posted 3 years ago #

    Okay, there is definitely something freaky going on here and I think it's Plesk related. I don't have a logical reason, but my Spider-sense is tingling. Without further editorial, here's the strange part:

    I used the same piece of code above and I used it in a static folder with simple straight-forward files ... and got the same error as above. File not found on this server.

  22. everwill
    Member
    Posted 3 years ago #

    Okay ... now let me ask you if I've discovered something truly strange or if this is just another FMC* error. I tinkered with the code (nominally) and then accidentally named the file ,htaccess (as in comma htaccess) and it worked like a champ. I renamed .htaccess and wham file not found. Changed it back to comma and all worked.

    -----------------------------------------
    *FMC error = An old programmer buddy would from time to time find that his code didn't work for no apparent reason. He went through the code line by line over and over and over. Of course, the problem wasn't the logic of the program it was nothing more than some obscure syntax problem hidden in a blur of characters. When after hours of seraching he finally found the error he would continually under his breath, "F****ing moronic child ... " Thus the origins of the FMC error.

  23. everwill
    Member
    Posted 3 years ago #

    Well, well, well ...

    Sorry for the multi-post but I'm also hoping that documenting my ineptitude will help the next stranger lost in the forest.

    I thought I was all clear but I just learned that ,htaccess works fine on one domain but is forbidden on another. So I am to assume that , and . mean something different in the mysterious world of htaccess ...

    The plot thickens.

  24. Yes, in the mysterious world of computers , and . are completely different. ;)

    .htaccess is the proper file name.

  25. everwill
    Member
    Posted 3 years ago #

    Yes but why would , work and . not work? Do you know what is the difference.

    BTW, I'm back onto thinking that this is and FMC-related error. And it's a case study in why things like this will make you go crazy.

    I have a plugin --- when you tell a tale of WP villainy there's always a plugin lurking in there somewhere --- that automatically writes a redirect when it detects certain changes. It does this to help you from breaking links. I discovered this when I tried to put the pieces of my puzzle back together and now I think this is the reason I was having bizarre nonsensical errors.

    So, without walking you through some of the details of my site, I'm going to try this again, but compensate for the plugin compensation and hopefully all will finally work.

  26. Yeah, strip it down to as close to a naked install as possible.

    No idea why ,htaccess worked. o_O

  27. Realistically, there's no system I know of that groks ,htaccess so more likely is that your setup doesn't like .htaccess at all.

    What happens if you make a blank file called .htaccess on the one with the ,htaccess?

  28. everwill
    Member
    Posted 3 years ago #

    I actually already have a few .htaccess redirects that are working without problem in other directories already. I've had success in the past with simple non-conditional stuff. I have to shake through a few kinks to compensate for the compensation as it were, so I'll come back to this when I have more info to share.

  29. Right, but you can exclude htaccess from working in specific directories in the server config. ;)

  30. everwill
    Member
    Posted 3 years ago #

    I assume you're talking about .htaccess and not ,htaccess? ;^)

Topic Closed

This topic has been closed to new replies.

About this Topic