• Resolved JimGR

    (@jimgr)


    Hello folks, I have searched high and low and need some help sorting out a 301 redirect using an .htaccess file. All sources I have found are very specific and incomprehensible to me, having not done this before. I’m at my wits end trying to decode Apache syntax with no experience.

    Basically, I have moved WP site to a new URL and hosting. I’m currently trying to redirect the old post URLs, which have had the same structure retained on the new site.

    My issue is the www version of the old URL is not redirecting, but the non-www is. In my old WP site it was installed in a subfolder ‘wordpress’ that didn’t display. I need 3 rules to be followed, where ‘*’ is a wildcard…
    1) https://www.olddomain.com/* –> newdomain.net/*
    2) oldomain.com/* –> newdomain.net/*
    3) non-essential, only for files: olddomain.com/wordpress/* –> newdomain.net/*

    Here is what is currently in my .htaccess file with any ‘rewrite’ stuff, the 301 redirect is the only one I have added myself:
    ————————————
    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www\.olddomain\.com
    RewriteRule (.*) https://newdomain.net/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/wordpress/
    RewriteRule ^(.*)$ /wordpress/ [L]

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress
    —————————

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    
    RewriteCond %{HTTP_HOST} !^www\.olddomain\.com
    RewriteRule (.*) https://newdomain.net/$1 [R=301,L]
    

    I think that rewrite condition is your problem. Basically this says: If the HTTP HOST is not www .olddomain.com, then redirect to newdomain.net.

    So, the www version is not redirecting because you are intentionally not redirecting for it.

    I think maybe you wanted this instead:

    
    RewriteCond %{HTTP_HOST} !^newdomain\.net
    RewriteRule (.*) https://newdomain.net/$1 [R=301,L]
    

    Now it says: If the HTTP HOST is not newdomain.net, then redirect to newdomain.net.

    If this is the .htaccess file for the new domain, why would you have any references to the old domain?
    If you still control the old domain (and it is hosted), you could have a different .htacces file and put rewrites to the new domain, but it is easier to just forward the entire domain at the registrar (no hosting).

    Thread Starter JimGR

    (@jimgr)

    Thank you @otto42, that seems to have sorted it out. I also removed the other rewrite stuff which seemed to fix some other issues.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Really struggling with 301 redirects’ is closed to new replies.