Redirect links to external sites using .htaccess

  1. quotations profile image93
    quotationsposted 6 years ago

    Hi Everyone,

    I am hoping that one of my fellow hubbers can help me with a coding problem. I would like to use htaccess mod_rewrite to change a large number of links (each with some variation) to a new external site. There are too many links to handcode and too many variables to do a search and replace.

    Here is what I would like to do:

    Current links examples:


    Would now be rewritten:

    The rewrite would be at the server level and the original html would remain.

    So that all links, regardless of the original url all point to the same page on the new site. I know I need to use wildcard variables to allow for the fact that the url pointing to has different html after but I have not been able to get it to work and when I googled this subject I couldn't find a site that answered my question.

    Thanks in advance for any help you can give me.

    (ps. I am using an apache server)

  2. pauldeeds profile image
    pauldeedsposted 6 years ago

    A rule like this in the .htaccess on the server will 301 redirect any URL on to the same URL at  For instance:

    RewriteRule (.*)$1 [R=301,L] ->

    If you need to match certain urls and rewrite them to something else on the new server, just change the rules.  For instance:

    RewriteRule ^foo/(.*).html$$1.php [R=301,L] ->