• Went from a static site to dynamic using wordpress after transferring the site from a different server to the current one I needed to upload an .htaccess file to keep google page rankings for search engines and tell crawlers of this 301 redirect. Because the new web server is on UNIX so the format to do this is like this:
    redirectMatch 301^(.*)$ https://www.mysite.com/index.html/
    redirectMatch permanent ^(.*)$ https://www.mysite.com/

    I noticed the site is also just using https:// without the WWW. and
    we wanted it with the www.

    Anyway when I uploaded my htaccess.txt file with all the old urls and new urls to redirect took out the .txt (.htaccess) there was already another .htaccess file there?
    with this in the file:

    # 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

    I tried to replace it because it’s really important that we keep our pagerank, and the site was disabled “page error” I had to put the origninal .htaccess file that was there. I even thought if I combined the two codes it would work and same thing the site didn’t work?

    How can I include my 301 redirect with this other file that was put there mysteriously?

Viewing 11 replies - 1 through 11 (of 11 total)
  • You should be able to just add the following to your .htaccess file:

    RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
    Thread Starter Crystal-27

    (@crystal-27)

    David thanks for your prompt response:

    For every old and new page 301 redirect I add the above code?

    redirectMatch 301^(.*)$ https://www.oldsite.com/index.html/
    redirectMatch permanent ^(.*)$ https://www.newsite.com/

    redirectMatch 301^(.*)$ https://www.oldsite.com/about.html/
    redirectMatch permanent ^(.*)$ https://www.newsite.com/about-us/

    redirectMatch 301^(.*)$ https://www.oldsite.com/site/programs.html
    redirectMatch permanent ^(.*)$ https://www.newsite.com/programs/

    etc, etc……

    Will I than delete the old .html files on the server?

    Thanks

    Thread Starter Crystal-27

    (@crystal-27)

    Am I replacing below with the above code you provided, or adding it like this?

    # 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>
    RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
    # END WordPress

    It doesn’t really matter.

    Crystal, I read your post quickly and overlooked the part where you redirecting individual pages as well. Sorry about that. The code I posted will fix the non-www issue.

    To redirect individual pages, try doing the following for each page URL:

    RewriteRule ^about.html$ https://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^work.html$ https://www.mydomain.com/our-work [L,R=301]

    If the above doesn’t work, try adding a leading / before like so:

    RewriteRule ^/about.html$ https://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ https://www.mydomain.com/our-work [L,R=301]
    Thread Starter Crystal-27

    (@crystal-27)

    Hi David:

    OK, in my file I got rid of the
    # 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 put in all the pages with:
    RewriteRule ^about.html$ https://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^work.html$ https://www.mydomain.com/our-work [L,R=301]

    That didn’t work
    I used the / before. That didn’t work.

    I realized it can’t run without the first code in there.
    # 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]
    RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
    RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
    RewriteRule ^/about.html$ https://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ https://www.mydomain.com/our-work [L,R=301]
    </IfModule>
    # END WordPress

    Ok so the site is working, but if I type in www. after the https:// it reverts to https://mydomain.com?

    Thread Starter Crystal-27

    (@crystal-27)

    Now I can’t log into my wp-Control Panel–yikes

    Thread Starter Crystal-27

    (@crystal-27)

    To make the site’s URL https://www., go into WordPress; Settings; General, and add the www to the WordPress URL and Site Address section!

    No! That can immediately trash your site & lock you out of your admin area.

    You should not be removing the code that WordPress places in the .htaccess file by default. It is needed to make the site run properly. Leave what is already in there and add the pieces I’ve talked about.

    Also, I’m assuming you are replacing “mydomain.com” with your actual domain, correct?

    Thread Starter Crystal-27

    (@crystal-27)

    It all works great now, I’m not locked out of my CPanel,
    and No I didn’t remove it.
    .htaccess file is now:
    # 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]
    RewriteRule ^/about.html$ https://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ https://www.mydomain.com/our-work [L,R=301]
    </IfModule>
    # END WordPress
    And to make the site’s URL https://www., I went into WordPress; Settings; General, and added the www to the WordPress URL and Site Address section!

    It works now!!!!!

    ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘.htaccess file can't be replaced to change URLs’ is closed to new replies.