htaccess redirect 301 needs to end if matched

Posted on 2013-10-14
Medium Priority
Last Modified: 2013-10-16

I have a site that has been moved from one domain to another and the URL's have been changed so I have many different redirect 301 i.e

redirect 301  /category/heath-and-beauty/herbs/ http://newdomain.com/health/into-the-bliss/category/heath-and-beauty/herbs/

this works fine but I wanted to add this rule so that if there is anything that does not match the redirect 301 then this rule will come into effect

Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) http://newdomain.com/health/into-the-bliss/$1 [R=301,L]

The problem is that when I add the above rewrite rule all the previous redirect 301 are ignored and it only used the RewriteRule. So I need to end the redirect 301 when a rule matches. I tried

redirect 301  /category/heath-and-beauty/herbs/ http://newdomain.com/health/into-the-bliss/category/heath-and-beauty/herbs/ [L]

but the [L] can only be used in a rewrite rule, is there a way to exit the rule on match on a redirect 301 that comes above the rewrite rule.

many thanks for your help
Question by:Lightwalker
  • 2
LVL 21

Accepted Solution

Julian Matz earned 2000 total points
ID: 39572795
What about this?

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/category/heath-and-beauty/herbs/$ http://newdomain.com/health/into-the-bliss/category/heath-and-beauty/herbs/ [R=301,L]
RewriteRule ^(.*)$ http://newdomain.com/health/into-the-bliss/$1 [R=301,L]

Open in new window


Author Closing Comment

ID: 39575407
Thank you julianmatz,
worked great, the only thing I had to change was the beginning slash  so the rewrite was:

RewriteRule ^category/heath-and-beauty/herbs/$ http://newdomain.com/health/into-the-bliss/category/heath-and-beauty/herbs/ [R=301,L]
LVL 21

Expert Comment

by:Julian Matz
ID: 39577499
No problem. Glad I could help.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question