301 Redirect Error

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

301 Redirect Error

Post by lprintz »

I've just finished a site, and while creating the 301 redirects, I came across an error. I have pretty URLs set up and they are working properly, however the redirects seem to be outputting "double urls."

Example:
"http://website.com/about.html" should redirect to "http://website.com/company-info/about-us.html", instead it is outputting "http://website.com/company-info/about-u ... about.html"

The redirect seems to be functioning OK, but it's adding a "?page=" followed by the old link that was originally typed in. My htaccess looks like this:

Code: Select all

<IfModule mod_rewrite.c>
 RewriteEngine On
 ErrorDocument 404 http://borislow.com/index.php

 redirect 301 /borislow/aboutBorislow.html http://borislow.com/about-us.html
 redirect 301 /borislow/history.html http://borislow.com/about-us/borislow-history.html
 redirect 301 /borislow/Bi_team.html http://borislow.com/about-us/meet-the-team.html
 redirect 301 /borislow/emplBenefitsdept.html http://borislow.com/about-us/meet-the-team/employee-benefits-department.html
 redirect 301 /borislow/InsuranceInvestmentDept.html http://borislow.com/about-us/meet-the-team/insurance-and-investment-department.html
 redirect 301 /borislow/operations.html http://borislow.com/about-us/meet-the-team/operations-and-administration.html
 redirect 301 /borislow/Directions.html http://borislow.com/about-us/directions.html
 redirect 301 /borislow/careers.asp http://borislow.com/about-us/careers.html
 redirect 301 /borislow/contactus.asp http://borislow.com/about-us/contact-us.html
 redirect 301 /borislow/newsevents.asp http://borislow.com/about-us/news-and-events.html
 redirect 301 /borislow/EmployerBlueprint.html http://borislow.com/employer-blueprint.html
 redirect 301 /borislow/EmployeeBenefits.html http://borislow.com/employer-blueprint/employee-benefits.html
 redirect 301 /borislow/GroupBenefits.html http://borislow.com/employer-blueprint/group-benefits.html
 redirect 301 /borislow/InsuranceCarriers.html http://borislow.com/client-resources/insurance-carriers.html
 redirect 301 /borislow/RegulatoryCompliance.html http://borislow.com/client-resources/legislative-regulatory-compliance.html
 redirect 301 /borislow/Publications.asp http://borislow.com/client-resources/publications.html
 redirect 301 /borislow/Glossary.html http://borislow.com/client-resources/glossary.html
 redirect 301 /borislow/EmployeeAdvantage.html http://borislow.com/employee-advantage.html
 redirect 301 /borislow/ConsumerChoice.html http://borislow.com/employee-advantage/consumer-choice.html
 redirect 301 /borislow/cultureWellness.html http://borislow.com/employee-advantage/culture-of-wellness.html
 redirect 301 /borislow/ComplementaryBenefits.html http://borislow.com/complementary-benefits.html
 redirect 301 /borislow/BorislowExperience.html http://borislow.com/bi-experience.html
 redirect 301 /borislow/Communication.html http://borislow.com/bi-experience/communication.html
 redirect 301 /borislow/Service.html http://borislow.com/bi-experience/service.html
 redirect 301 /borislow/Results.html http://borislow.com/bi-experience/results.html
 redirect 301 /borislow/ComplementaryBenefits.html http://borislow.com/complementary-benefits.html
 redirect 301 /borislow/hrbenefits.html http://borislow.com/client-resources/hr-and-benefit-resources.html
 redirect 301 /borislow/hrbenefits.html http://borislow.com/client-resources/hr-and-benefit-resources.html
 redirect 301 /borislow/InsuranceInvestmentRes.html http://borislow.com/client-resources/insurance-and-invetsments.html
 redirect 301 /borislow/StrategicAlliances.html http://borislow.com/client-resources/strategic-alliances.html
 redirect 301 /borislow/InsuranceIndustry.html http://borislow.com/client-resources/insurance-industry.html
 redirect 301 /borislow/HealthWellness.html http://borislow.com/client-resources/health-and-wellness.html
</IfModule>
  
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /
 
  # 301 Redirect all requests that don't contain a dot or trailing slash to
  # include a trailing slash
  # except for form POSTS
  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{REQUEST_URI} !\.
  RewriteCond %{REQUEST_METHOD} !POST$
  RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
 
  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]
Please help! Thanks in advance.
vigor
Forum Members
Forum Members
Posts: 92
Joined: Sat Apr 25, 2009 2:32 pm

Re: 301 Redirect Error

Post by vigor »

Hi,

did you find a solution to this as I now have the same problem.

Thanks
replytomk3

Re: 301 Redirect Error

Post by replytomk3 »

I have posted about this problem already and got no responses.
vigor
Forum Members
Forum Members
Posts: 92
Joined: Sat Apr 25, 2009 2:32 pm

Re: 301 Redirect Error

Post by vigor »

Got this to work for me in the end using the code below.Hope it helps

Code: Select all

RewriteRule ^oldpage/$ http://www.yourdomain.com/newpage/ [R=301,L]
replytomk3

Re: 301 Redirect Error

Post by replytomk3 »

With about half an hour of tweaking, I got it to work.

To summarize:

Old 301 rewrite rule was something like

Code: Select all

redirect 301 /portals/electronics-as-a-hobby/general-and-misc-2.html http://wiki.mkrd.info/Electronics_as_a_Hobby_portal
To convert to a RewriteRule, use a ^ character. I think that this does pattern matching. Do not use opening "/". Add $ at the end of old page URL.

Any one character off will break the rewrite functionality.

Code: Select all

RewriteRule ^portals/electronics-as-a-hobby/general-and-misc-2.html$ http://wiki.mkrd.info/Electronics_as_a_Hobby_portal [R=301,L]
Is the code to redirect a .html page that used to be within subfolders (as far as could be seen from outside CMSMS) (or parent pages in CMSMS) /portals and /electronics-as....
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 204
Joined: Sun Sep 05, 2010 6:11 am

Re: 301 Redirect Error

Post by chrisbt »

Brilliant post thanks - was struggling with this:

The following worked perfectly for me.

Code: Select all

# Page specific 301 redirects
RewriteRule ^oldpage$ http://www.yourdomain.com/newpage [R=301,L]
However it had to be placed, just after:

Code: Select all

RewriteBase /
and before the rest of the rewrite rules in the .htaccess file.
Post Reply

Return to “The Lounge”