I had a laravel project on a sub-domain and I migrated to another sub-domain.
I want to redirect all requests from old sub-domain to the new one.
For example:
https://old.website.com
https://old.website.com/login
https://old.website.com/contact
Should become:
https://new.website.com
https://new.website.com/login
https://new.website.com/contact
I moved all the files to another folder and added .htaccess
with the following code:
RewriteEngine On
RewriteRule ^(.*)$ https://new.website.com/$1 [R=301,L]
But the issue is that public
is added to the url for example:
https://old.website.com
Becomes:
https://new.website.com/public
So I get 404 not found error.
For the sub-domain I set the document root to point to public folder so no need to add the public directory to the url.
2
Answers
By the sounds of it, you likely have an internal rewrite to the
/public
subdirectory. Try the following instead:Test with 302 (temp) redirect first to avoid potential caching issues. You will need to clear your browser cache before testing.
I have this solution on one of my projects. To redirect requests from old sub-domain to the new one without the public folder in the URL, you could need to modify the .htaccess file. You can try the following code:
This should redirect all requests to the new sub-domain while preserving the rest of the URL. This way, you should be able to access the pages at their new URL without encountering a 404 error.