Redirect a single URL to the same URL on another domain

Redirect a single URL to the same URL on another domain - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect a single URL to the same URL on another domain error on your web browser. Problem :


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


Solution :

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]



Just links that start http://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$ http://www.destination-website.com/$0 [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.



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 http://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 http://www.destination-website.com/click-4559226-10388358


Redirect and RedirectMatch will pass the query string along to the target url unchanged.


On www.my-website.com:

We hope that this article has helped you resolve the htaccess, redirects, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

Redirected urls show in serp, with the original permalink but with the title and meta of the target page

How can I redirect everything but the index as 410?

How do I redirect traffic only if being accessed from a specific port?