• 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:

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

    You’ll end up at
    https://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 ^(.*)$ https://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 https://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?

Viewing 15 replies - 1 through 15 (of 30 total)
  • Thread Starter everwill

    (@everwill)

    Maybe I put this in the wrong forum?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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(.*)$ https://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(.*)$ https://target-site.com/topic-x$1 [R=301,NC,L]

    That’s untested, though.

    Thread Starter everwill

    (@everwill)

    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(.*)$ https://target-site.com/topic-x$1 [R=301,NC,L]
    Thread Starter everwill

    (@everwill)

    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! ;^)

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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.

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

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

    Thread Starter everwill

    (@everwill)

    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(.*)$ https://nesbitt-realty.com/idx/$1 [R=301,NC,L]

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

    https://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.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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(.*)$ https://nesbitt-realty.com/idx$1 [R=301,NC,L]

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

    Thread Starter everwill

    (@everwill)

    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(.*)$ https://condo-alexandria.com/idx$1 [R=301,NC,L]

    In other words I swapped the URLs to see what would happen. Browsed to https://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.

    Thread Starter everwill

    (@everwill)

    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.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Hmmm. Whatever generates the destination shouldn’t matter.

    The goal is ‘Anyone who goes to https://condo-alexandria.com/idx/mls-fx7500562-8220_crestwood_heights_dr_704_mclean_va_22102 should be redirected to https://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?

    Thread Starter everwill

    (@everwill)

    You have described the goal accurately, but to be crystal clear the goal is to have anything that goes to https://condo-alexandria.com/idx/ANYTHING go to https://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.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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/(.*)$ https://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)

    the goal is to have anything that goes to https://condo-alexandria.com/idx/ANYTHING go to https://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.

    Thread Starter everwill

    (@everwill)

    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.

    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.

Viewing 15 replies - 1 through 15 (of 30 total)
  • The topic ‘Infinite redirect / Conditional .htaccess’ is closed to new replies.