I am in the process of migrating a static website to Symfony 4. I would like to redirect the old URLs to their corresponding routes in the new Symfony 4 app (while keeping the same domain name), like so:
https://www.old-site-url.com/contact.html to https://www.old-site-url.com/contact
I have tried specifying a redirect rule in the htaccess (located in the project root) :
RewriteRule https://www.old-site-url.com/contact.html$ https://beta.old-site-url.com/about [R=301,L]
Note: I redirect one URL to the beta subdomain during the testing phase.
However the redirections still wouldn't work. What am I doing wrong?
Thank you!
You cannot match HOST_NAME
in RewriteRule
. You must use a RewriteCond
for that like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?old-site-url\.com$ [NC]
RewriteRule ^contact\.html$ https://beta.old-site-url.com/contact [R=301,L,NC]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.