?
Solved

301 redirect using HTACCESS

Posted on 2011-09-22
7
Medium Priority
?
318 Views
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 http://www.domain.com/products/car.html they are redirected to www.newdom.com/car.html

Is that possible?

Thanks
0
Comment
Question by:fox_statton
[X]
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
7 Comments
 
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+)$ 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
 

Author Comment

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

Expert Comment

by:Dushyant Sharma
ID: 36579589
does www.newdomain.com/car.html works? i mean the new domain has the same file name as the old one has?
0
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

by:fox_statton
ID: 36579618
Yep, same name etc.
0
 
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 ^/(.*) 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
 
LVL 14

Accepted Solution

by:
Dushyant Sharma earned 2000 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.
0
 

Author Closing Comment

by:fox_statton
ID: 36579679
Great, many thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

718 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