0

I am trying to redirect my website from old domain to new domain using htaccess. Both the websites have same pages with same url structure i only need to redirect the main url part i-e https://test.com old url to https://test1.com with other pages url as well. For example if i had a page in old website (https://test.com/page1) it should be redirected to (https://test1.com/page1). I used this code to redirect it but its not working any help.

Redirect 301 /page1/ https://test1.com/page1

Redirect 301 https://test1.com
Abbasi
  • 588
  • 1
  • 7
  • 26
  • Possible duplicate of [Htaccess redirect all files from subdirectory in one domain to another domain](http://stackoverflow.com/questions/16864690/htaccess-redirect-all-files-from-subdirectory-in-one-domain-to-another-domain) – Alberto Anderick Jr Apr 27 '17 at 18:21
  • If any of our answers have helped, please upvote or accept any that have helped :) – LatentDenis Apr 28 '17 at 13:40

2 Answers2

0

You might find these helpful:

#Redirect from old domain to new domain
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

and

#Redirect from old domain to new domain with full path and query string:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

Feel free to follow the resource: https://gist.github.com/ScottPhillips/1721489

LatentDenis
  • 2,839
  • 12
  • 48
  • 99
0

The first Redirect has a different source and target URL-path. The old URL has a trailing slash and new one has not.

Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL.

This means, if you request

http://old.example.com/page1/some/script.php

the path beyond /page1/ (some/script.php without leading slash) will be taken and attached to the target /page1

http://new.example.com/page1some/script.php

To have the complete path appended, you must omit the trailing slash in the old URL-path, e.g.

Redirect /page1 https://test1.com/page1

To address the second Redirect, this will only work inside a Location directive, e.g.

<Location "/page1">
    Redirect https://test1.com/page1
</Location>

Finally, when everything works as it should, you may change the status code to 301. Never test with 301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198