How to Redirect Old URL to New URL using .htaccess File


Sometimes needs to change the URL structure for SEO or other purposes. In that case, the old URL shows 404 error which is very confusing for the website’s visitor. To avoid this situation, you can redirect the old page (non-existing) request to new page URL by the .htaccess file.

Using .htaccess file you can redirect users from an old URL to new URL without having to keep the old page. This tutorial shows how to redirect a URL to another URL using a .htaccess file.

Redirect URL to Another URL

Redirect /path/to/old.html /path/to/new.html

Redirect URL with RewriteRule
The following code redirect items.php?id=123 to products.html.

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+items\.php\?id_id=123[&\s] [NC]
RewriteRule ^ /products.html/? [R=302,L]

Leave a reply