Mobile app version of vmapp.org
Login or Join
Berumen354

: 301 redirect with Apache: All paths of URL to a single path I am migrating a website from one platform to another, and in that process, I'm getting rid of the old domain name. There is no

@Berumen354

Posted in: #301Redirect #Apache2 #Redirects

I am migrating a website from one platform to another, and in that process, I'm getting rid of the old domain name.
There is no direct relation between the paths on the old and new website, and therefore, I want to redirect all old paths to the new websites' front page: I.e. olddomain.example/any_path should redirect to the front page of newdomain.example.
I am aware of the SEO consequences of this.

My current solution is to use the RedirectPermanent directive, so that my .htaccess in the domain's root directory contains:

RedirectPermanent / newdomain.example/

How do I achieve that any path on olddomain.example (e.g. olddomain.example/any_path) is redirected to the front page (and not the corresponding path) of newdomain.example?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Berumen354

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

My current solution is to use the RedirectPermanent directive


The RedirectPermanent (mod_alias) directive is prefix matching so, as you have found, you will be redirected to the "corresponding path" on the newdomain.

However, the complementary mod_alias directive RedirectMatch matches using a regex and will allow you to redirect all URLs to the single root URL.

RedirectMatch 301 / newdomain.example/

This is marginally preferable to using mod_rewrite (RewriteRule), unless you are already using mod_rewrite for other redirects.

10% popularity Vote Up Vote Down


 

@Alves908

I think this should do the trick for you. On the old domain, put this code in the .htaccess file (this assumes a 301 redirect is used).

RewriteEngine On
RewriteRule (.*) newdomain.example [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme