I have an old website which i deleted everything on the sever. Now i want to redirect it to the new website. And i want it to be like this:
1.old.com => new.com
2.old.com/product=>new.com/product
Just these 2 redirects. I tried to install the prestashop on the old website to redirect.I tried to add this to the .httaccess ( i installed the prestashop on the blank sever) but it did not work.
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]
Please help me. Thank you a lot
CodePudding user response:
You need to add %{REQUEST_URI} parameter.
RewriteRule ^.*$ http://newdomain.com%{REQUEST_URI} [R=301]
CodePudding user response:
Well, you ask for exactly two redirections. So you should implement exactly two redirections:
RewriteEngine on
RewriteRule ^/?$ https://new.example.com/ [R=301,END]
RewriteRule ^/product/?$ https://new.example.com/product [R=301,END]
This relies on the name resolutions for old.example.com and new.example.com to point to different systems. If both names resolve to the same system then you need to add a condition to prevent a redirection loop:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^old\.example\.com$
RewriteRule ^/?$ https://new.example.com/ [R=301,END]
RewriteCond %{HTTP_HOST} ^old\.example\.com$
RewriteRule ^/product/?$ https://new.example.com/product [R=301,END]
Any other request will then result in a 404 status, assuming that the old host name is still served by some other system.
In general I would recommend to implement such rules in the actual http server's configuration of the host "old.example.com" instead of using a distributed configuration file (".htaccess").