Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm trying to set up my .htaccess file to take the displayed link and route it to the destination link as below

Displayed Link http://www.my-website.com/click-4559226-10388358?url=https%3A%2F%2Fdestination-website2.com%2FItem.php%3Fid%3D44350396%26sld%3DA6D7A632-821E-4b78-ACD0-147658B77BD6

Destination Link http://www.destination-website.com/click-4559226-10388358?url=https%3A%2F%2Fdestination-website2.com%2FItem.php%3Fid%3D44350396%26sld%3DA6D7A632-821E-4b78-ACD0-147658B77BD6

Effectively, all that changes is the first URL (http://www.my-website.com) everything after that is the same.

Is this possible and could someone briefly explain how I would go about it?

* Just to be clear, I don't want to redirect everything from my-website.com. Just links that start http://www.my-website.com/click-4559226-10388358

share|improve this question
add comment

migrated from stackoverflow.com Feb 10 '11 at 19:32

This question came from our site for professional and enthusiast programmers.

3 Answers

On www.my-website.com:

Redirect permanent / http://www.destination-wabsite.com/
share|improve this answer
add comment

Try this in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

If it's not keeping the query string, try changing the last line of the code above to

RewriteRule / http://www.newdomain.com/?%{QUERY_STRING} [R=301,L]

edit:

If you only want to limit the rule to www.my-website.com/click-4559226-10388358, then try changing the last line of the code above to this:

    RewriteRule ^click\-([0-9]+)\-([0-9]+)$ http://www.newdomain.com/click-$1-$2?%{QUERY_STRING} [R=301,L]
share|improve this answer
    
Thanks, but I don't want to redirect everything from my-webiste.com. Just links that start http://www.my-website.com/click-4559226-10388358 –  Anonymous Feb 10 '11 at 19:29
    
See the edit above –  Emmanuel Feb 10 '11 at 19:36
add comment

Assuming mod_rewrite is enabled on your server, you would want to put something like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.my-website\.com$ [NC]
RewriteRule ^(.*)$ http://www.destination-website.com/$1 [QSA,L]
</IfModule>

This will redirect any requests to www.my-website.com to www.destination-website.com. The [NC] tells Apache to operate in case insensitive mode and the [QSA,L] tells it to maintain any querystring parameters and that no other rules should be followed. More information can be found on Apache's website.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.