Redirect old url to new url htaccess

To redirect an old URL to a new URL using .htaccess file, you can use the Redirect or RedirectMatch directive. Here are some examples:

Redirect a specific old URL to a new URL

Redirect 301 /old-url http://example.com/new-url

This will redirect any requests to /old-url to http://example.com/new-url.

Redirect all URLs with a specific pattern to a new URL

RedirectMatch 301 ^/old-pattern http://example.com/new-url

This will redirect any URLs that match the pattern /old-pattern to http://example.com/new-url.

Redirect all URLs from an old domain to a new domain

Redirect 301 http://old-domain.com http://new-domain.com

This will redirect any requests from http://old-domain.com to http://new-domain.com.

Redirect all URLs from an old subdomain to a new subdomain

Redirect 301 http://old-subdomain.old-domain.com http://new-subdomain.new-domain.com

This will redirect any requests from http://old-subdomain.old-domain.com to http://new-subdomain.new-domain.com.

Redirect all URLs with a specific query string to a new URL

RedirectMatch 301 ^/(.*)\?old-query-string http://example.com/new-url?new-query-string

This will redirect any URLs that match the pattern /old-pattern?old-query-string to http://example.com/new-url?new-query-string.

Note:

It's also important to note that you can use mod_rewrite rules to achieve more complex redirects. For example:

RewriteEngine On
RewriteRule ^old-url$ http://example.com/new-url [R=301,L]

This will redirect any requests to /old-url to http://example.com/new-url.