Solved

301 redirect using HTACCESS

Posted on 2011-09-22
7
313 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 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.
0
 

Author Closing Comment

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

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

829 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