Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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
0
fox_statton
Asked:
fox_statton
  • 4
  • 3
1 Solution
 
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
 
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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
 
Dushyant SharmaCommented:
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
 
fox_stattonAuthor Commented:
Great, many thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now