• Hello,

    I have wordpress installed in a subdirectory, but have changed the settings when the site went live to remove the subdirectory from the url. Unfortunately Google has indexed the site including the subdirectory, so those pages now display a 404 error when linked from Google.

    Is there any way to redirect those links to remove the subdirectory?

    Here’s my htaccess file that’s in the root folder at the minute but it’s not working:

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} ^subdir [NC]
    RewriteRule ^subdir/(.+)$ https://www.mydomain.co.uk/$1 [R=301,L]
    
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.mydomain.co.uk/$1 [R=301,L]
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mydomain.com$
    RewriteRule ^/?$ "https\:\/\/www\.mydomain\.co.uk" [R=301,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

    and here’s my htaccess file in the subdirectory, also not working:

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} ^subdir [NC]
    RewriteRule ^subdir/(.+)$ https://www.mydomain.co.uk/$1 [R=301,L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /subdir/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /subdir/index.php [L]
    </IfModule>
    
    # END WordPress

    Many thanks for any advice.

  • The topic ‘WordPress subdirectory install redirect problem’ is closed to new replies.