This is with Apache 2.4 webserver.

I copied the hole site from one domain to another. Let us say from olddomain.com to newdomain.com/subdir/. The site is a webservice with news and advertisements.

The site has the php application that is adverisement server. This application has many links to olddomain.com in the code, in config files etc. So links are to the old domain. These links are literal, not any relative.

May I do anything to redirect all those link to the newdomain? I was thinking about something like .htaccess with redirection but in fact I have no idea to which folder place such a .htaccess.

How to redirect links?

  • use regex (if you dare) to replace links. Or better, write another php script that loads html file using file_get_contents then uses xpath to replace links – gwillie May 19 '17 at 3:39
  • 1
    The proper way to fix this issue is to fix the code. – ivanivan May 19 '17 at 5:04

Assuming you own the old domain, this looks like a job for the mod_alias Apache module, and here's a guide.

Here is some documentation on the Redirect & RedirectMatch directives it provides.

Or, if you're trying to do something fancy there's also the mod_rewrite module.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.