Home > Back-end >  Hidden redirect domain name to a subfolder of an other DN using .htaccess or anything else
Hidden redirect domain name to a subfolder of an other DN using .htaccess or anything else

Time:03-26

I want to redirect my domain name example.com to this domaine name : example2.com/new/mywebsite without changing the url(a hidden redirection) I tried several codes in stackoverflow but it didnt work for me..

Ps : example2.com is a different website, actualy i did 2 websites with the same dashbord in wordpress the same hosting but with a different domains name.

Example 1 that doesnt work :

RewriteEngine On
RewriteCond %{HTTP_HOST} ^((www.)?)example1.com [NC]
RewriteRule ^folder/(.*)$ https://example2.com/new/website-a/$1 [R=301,L]

Example 2 that dosnt work too :

RewriteEngine On
RewriteCond %{HTTP_HOST} ^website-a\.example1\.com$
RewriteRule ^(.*)$ https://example2.com/new/website-a/$1 [L,R=301]

CodePudding user response:

Based on specifically what you're asking for in your first paragraph, this should work:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example1.com$ [NC]
RewriteRule ^(.*)$ https://example2.com/new/mywebsite [R=301,L]

But your examples are using different paths etc so make sure you update as needed.

Your Apache configuration files also need to be updated to ensure that AllowOverride All is set rather than AllowOverride None

This file needs to be put in the root folder of your example1 (old) domain. This is because the redirect is started when you visit the example1 site.

  • Related