WordPress.org

Forums

[resolved] .htaccess (5 posts)

  1. ccarlow
    Member
    Posted 2 years ago #

    Trying to understand how to redirect old website links to new wp pages using .htaccess.

    I used the HTML Import 2 to import old site files to wp on a new service provider/server. This plugin gave me redirect codes to copy and paste in the .htaccess file which I tried but I got a error code 500. I have about 200 redirects from the old website to the new page names just to note.

    My .htaccess file is listed below the questions I have. Everything above the comment "# Begin my redirects" was original working code. I don't understand this coding much and did a lot of reading on the internet with very little luck. I did find if I write the redirects differently it will work i.e.
    "redirect 301 /Acupuncture.htm http://www.natureshealing.info/acupuncture-4/"
    My questions are as follows:
    1. Is the # Begin my redirects code positioned in the right place i.e. after the # END WordPress block of code?
    2. What is the proper coding format for these redirect statements?
    3. How do I make the code case-insensitive? I tried to add [NC] at the end of the redirect statement but it didn't work.

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php
    
    # 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
    
    # Begin my redirects
    Redirect	http://www.natureshealing.info/Acupuncture.htm	http://www.natureshealing.info/acupuncture-4/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Articles.htm	http://www.natureshealing.info/articles-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Charts.htm	http://www.natureshealing.info/charts-6/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/ChiKungTaiCHiForms.htm	http://www.natureshealing.info/chikungtaichiforms-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Classes.htm	http://www.natureshealing.info/classes-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/ClinicInfo.htm	http://www.natureshealing.info/clinicinfo-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Conditions_Treated.htm	http://www.natureshealing.info/conditions_treated-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/ContactUs.htm	http://www.natureshealing.info/contactus-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Diet.htm	http://www.natureshealing.info/diet-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Directions.htm	http://www.natureshealing.info/directions-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/EvidenceBasedProtocols.htm	http://www.natureshealing.info/evidencebasedprotocols-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/FAQ.htm	http://www.natureshealing.info/faq-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/FriendsONH.html	http://www.natureshealing.info/friendsonh-5/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/Health-HarmonyClassroom.htm	http://www.natureshealing.info/health-harmonyclassroom-6/	[R=301,NC,L]
    Redirect	http://www.natureshealing.info/HerbalMedicine.htm	http://www.natureshealing.info/herbalmedicine-5/	[R=301,NC,L]
    # END My redirects
  2. Jesús Franco
    Member
    Posted 2 years ago #

    I don't know exactly how that plugin works but, are you sure the rules should go after WP rules? I think they should go before

  3. ccarlow
    Member
    Posted 2 years ago #

    I tried placing my redirect rules before and after and it didn't matter - still got the error 500.

    But I did finally correct this problem. I had to go through each line of code and test it - probably more than 200 redirects. Ugg!

    I changed the code layout - I found a correct format for .htaccess files here at the following web address: http://perishablepress.com/case-insensitive-redirectmatch/

    Instead of:
    Redirect http://www.natureshealing.info/Acupuncture.htm http://www.natureshealing.info/acupuncture-4/ [R=301,NC,L]
    I used:
    RedirectMatch 301 (?i)http://www.natureshealing.info/Acupuncture.htm http://www.natureshealing.info/acupuncture-4/
    note: no domain in the 1st part of the rule referencing the old website; also the flags are positioned earlier - 301 & the nocase flag is written as (?i) - case insensitive.

    I also found I was actually getting 2 errors. 1. The page would endlessly try to load but nothing would appear - the reason I believe was because I had a redirect based on the original index.htm page that probably caused a loop i.e.: Redirect 301 (?i)/index.htm http://www.natureshealing.info/index/

    2nd problem: I had a space in one of my redirect rules for a web address i.e. natureshealing.info /blablabla instead of natureshealing.info/blablabla.

    Once I corrected the two errors and rewrote the rules in a proper format it worked!

  4. ccarlow
    Member
    Posted 2 years ago #

    sorry I'll mark it solved

  5. Jesús Franco
    Member
    Posted 2 years ago #

    thanks a lot for sharing the solution with the community!

Topic Closed

This topic has been closed to new replies.

About this Topic