301 redirect using HTACCESS

Posted on 2011-09-22
Last Modified: 2012-06-27
Hi all,

I am moving part of my site to a new domain, and wondered if there was a way to automatically generate 301 responses using htaccess based on the requested URL

For example, I want an htaccesss in the /products folder so that when someone tries to get to they are redirected to

Is that possible?

Question by:fox_statton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 36579295
well you can get the pattern and write a rewrite rule for every pattern. for example for each folder you can write the redirects as below:

RedirectMatch 301 (.*)\/product\/(\w+)$$1

for httpd.conf based redirects please refer the below

Author Comment

ID: 36579568
I tried that, but it didnt work, just gave a 404 error
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 36579589
does works? i mean the new domain has the same file name as the old one has?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 36579618
Yep, same name etc.
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 36579637
oops sorry.. my mistake. inside .htaccess you need not to mention the folder name :)

RedirectMatch 301 ^/(.*)$1

here put this inside .htacess file in the folder and change the domain name to the desired one. hope this helps
LVL 14

Accepted Solution

Dushyant Sharma earned 500 total points
ID: 36579649
remember everything at this point and below will be forwarded. if you want more restrictions then you should create it as redirect rules by getting the uri first.

Author Closing Comment

ID: 36579679
Great, many thanks!

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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…

630 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