WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] htaccess to move all site access except wp-admin? (3 posts)

  1. jeremyduffy
    Member
    Posted 3 years ago #

    I'm doing htaccess to redirect http://www.d1.com/anything to http://www.d2.com/anything and it works, but I want it to NOT redirect when accessing just http://www.d1.com or http://www.d1.com/wp-admin. I'm stuck on the rewritecond rules that would make that happen.

    Here's what I have so far

    rewritecond %{HTTP_HOST} ^www.d1.com$ [NC]
    rewriterule ^(.*)$ "http\:\/\/d2\.com\/$1" [R=301,L]

    I think I need this too:

    rewritecond %{HTTP_HOST} !^www.d1.com\/wp-admin$ [NC]

    But I can't figure out how to make it NOT redirect if they just got to http://www.d1.com.

  2. jeremyduffy
    Member
    Posted 3 years ago #

    Ok, I think I figured it out, though I'm sure this is ugly and very wrong:

    rewritecond %{HTTP_HOST} ^www.d1.com$ [NC]
    rewritecond %{REQUEST_URI} ^...+ [NC]
    rewritecond %{REQUEST_URI} !^/wp-admin [NC]
    rewritecond %{REQUEST_URI} !^/index [NC]
    rewriterule ^(.*)$ "http\:\/\/d2\.com\/$1" [R=301,L]

    line one matches domain1
    line 2 requires that the part that comes after http://www.d1.com must be non-0 in length
    line 3 says it can't be wp-admin and line 4 says it can't be index

    This redirects only if it's not just http://www.d1.com, http://www.d1.com/wp-admin, or http://www.d1.com/index.php (and it seems to work)

  3. jeremyduffy
    Member
    Posted 3 years ago #

    Nope, that didn't work well at all. It ended up causing some kind of recursive loop on my page. I think it was actually due to another redirection of some kind, but either way things went bad.

Topic Closed

This topic has been closed to new replies.

About this Topic