301 redirect using HTACCESS

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 http://www.domain.com/products/car.html they are redirected to www.newdom.com/car.html

Is that possible?

Thanks
fox_stattonAsked:
Who is Participating?
 
Dushyant SharmaConnect With a Mentor Commented:
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.
0
 
Dushyant SharmaCommented:
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+)$ http://www.newdomain.com/$1

for httpd.conf based redirects please refer the below

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
0
 
fox_stattonAuthor Commented:
Hi,
I tried that, but it didnt work, just gave a 404 error
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Dushyant SharmaCommented:
does www.newdomain.com/car.html works? i mean the new domain has the same file name as the old one has?
0
 
fox_stattonAuthor Commented:
Yep, same name etc.
0
 
Dushyant SharmaCommented:
oops sorry.. my mistake. inside .htaccess you need not to mention the folder name :)

RedirectMatch 301 ^/(.*) http://www.thewebgoodies.com/$1

here put this inside .htacess file in the folder and change the domain name to the desired one. hope this helps
0
 
fox_stattonAuthor Commented:
Great, many thanks!
0
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.

All Courses

From novice to tech pro — start learning today.