homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Need help replacing part of URL
Using htaccess to insert extra directory names

 2:35 pm on Apr 18, 2012 (gmt 0)

Greetings all,

I have been searching through the forums for about an hour and just can't seem to get what I want to work, although this seems like it should be simple enough. Here is what I have:

Current URL:

New URL:

So we are consolidating a few things on our menu and tucking them into another category.

So I need to be able to redirect any users that try to use the current URL over to the new url by adding in NEWCAT to the URL.

I currently have this in my htaccess, which isn't working:

RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteRule ^products/cat1/(.*)$ /products/NEWCAT/cat1$1 [R=301,L]

Hope this makes sense, and thanks for any help.



 10:11 pm on Apr 18, 2012 (gmt 0)

Throw out the HTTP_HOST line. You don't need it. In fact, one job of your Redirect is to get everyone on the same page. Give the complete protocol and domain name, as in:

RewriteRule ^products/cat1/(.*)$ http://www.example.com/products/NEWCAT/cat1$1 [R=301,L]

As I typed out this line, a simple error jumped up and hit me in the face. I hope it's the same one you were running into. Hint: Move one parenthesis. In your rule as written, there are at least three equally valid solutions.


 12:40 pm on Apr 19, 2012 (gmt 0)

Hey Lucy,
Thank you for your help! I admit I am still pretty new to this stuff, but trying to read over everything I can to learn. I modified mine slightly from what you have (I assume this is what you meant by your hint):

RewriteRule ^products/backplanes(.*)$ http://www.example.com/products/single-board-computers/backplanes$1 [R=301,L]


 6:23 pm on Apr 19, 2012 (gmt 0)

Yup. Slash on both sides, otherwise you're redirecting to "backplanesblahblah" which probably does not exist. Or, if you had made the opposite mistake, "backplanes//blahblah".


 7:16 pm on Apr 19, 2012 (gmt 0)

Thanks again for the help! I will get the hang of this one day :)


 1:22 pm on Apr 23, 2012 (gmt 0)

Wait. Hold it right there and then back up one.

URLs for product pages do not need to specify any of the category names as folders.

Sure, list your products in categories and have a heirarchy of categories, but don't specify category names in the actual product URLs.

The benefits of this will be blindingly obvious once you try to implement any sort of multi-faceted navigation system.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved