WordPress.org

Forums

.htaccess file can't be replaced to change URLs (12 posts)

  1. Crystal-27
    Member
    Posted 4 years ago #

    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^(.*)$ http://www.mysite.com/index.html/
    redirectMatch permanent ^(.*)$ http://www.mysite.com/

    I noticed the site is also just using http:// 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?

  2. David Calhoun
    Member
    Posted 4 years ago #

    You should be able to just add the following to your .htaccess file:

    RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
  3. Crystal-27
    Member
    Posted 4 years ago #

    David thanks for your prompt response:

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

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

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

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

    etc, etc......

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

    Thanks

  4. Crystal-27
    Member
    Posted 4 years ago #

    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 ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
    # END WordPress

  5. esmi
    Forum Moderator
    Posted 4 years ago #

    It doesn't really matter.

  6. David Calhoun
    Member
    Posted 4 years ago #

    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$ http://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^work.html$ http://www.mydomain.com/our-work [L,R=301]

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

    RewriteRule ^/about.html$ http://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ http://www.mydomain.com/our-work [L,R=301]
  7. Crystal-27
    Member
    Posted 4 years ago #

    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$ http://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^work.html$ http://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 ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    RewriteRule ^/about.html$ http://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ http://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 http:// it reverts to http://mydomain.com?

  8. Crystal-27
    Member
    Posted 4 years ago #

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

  9. Crystal-27
    Member
    Posted 4 years ago #

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

  10. esmi
    Forum Moderator
    Posted 4 years ago #

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

  11. David Calhoun
    Member
    Posted 4 years ago #

    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?

  12. Crystal-27
    Member
    Posted 4 years ago #

    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$ http://www.mydomain.com/about-us [L,R=301]
    RewriteRule ^/work.html$ http://www.mydomain.com/our-work [L,R=301]
    </IfModule>
    # END WordPress
    And to make the site's URL http://www., I went into WordPress; Settings; General, and added the www to the WordPress URL and Site Address section!

    It works now!!!!!

    :)

Topic Closed

This topic has been closed to new replies.

About this Topic