: Redirect a single URL to the same URL on another domain 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
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 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 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 www.my-website.com/click-4559226-10388358
More posts by @Berumen354
4 Comments
Sorted by latest first Latest Oldest Best
If all that's changing is the query string, it should be possible to do this without mod_rewrite. Using a straightforward Redirect directive is more efficient, and often significantly faster than regular expression matching with a RedirectRule. Here's the Redirect statement, in an .htaccess file in the root of your site:
Redirect /click-4559226-10388358 www.destination-website.com/click-4559226-10388358
As w3d has pointed out, you should test that before changing to a permanent redirect:
Redirect 301 /click-4559226-10388358 www.destination-website.com/click-4559226-10388358
Redirect and RedirectMatch will pass the query string along to the target url unchanged.
Just links that start www.my-website.com/click-4559226-10388358
To redirect just the links where the URL-path is (exactly) /click-4559226-10388358 to the same URL on another domain, whilst maintaining the query string, then you can do something like the following in the .htaccess file in the document root.
This uses mod_rewrite, and should come near the top of the file if you have other directives:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?my-website.com$ [NC]
RewriteRule ^click-4559226-10388358$ www.destination-website.com/[CO] [R=302,L]
If the source and destination domains are located on different servers then you can omit the RewriteCond directive.
Change the 302 (temporary) redirect to 301 (permanent) when you are sure it's working OK. Permanent redirects are cached by the browser and so can cause problems when testing.
Try this in your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ www.newdomain.com/ [R=301,L]
If it's not keeping the query string, try changing the last line of the code above to
RewriteRule / www.newdomain.com/?%{QUERY_STRING} [R=301,L]
edit:
If you only want to limit the rule to my-website.com/click-4559226-10388358, then try changing the last line of the code above to this:
RewriteRule ^click-([0-9]+)-([0-9]+)$ www.newdomain.com/click--?%{QUERY_STRING} [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.