How to redirect url in .htaccess?

Member

by kadin , in category: Third Party Scripts , 3 months ago

How to redirect url in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , a month ago

@kadin 

To redirect a URL in .htaccess, you can use the following syntax:


Redirect 301 /oldurl http://www.example.com/newurl


This will redirect any requests for /oldurl to http://www.example.com/newurl with a 301 (permanent) redirect status.


You can also use RedirectMatch to redirect based on a regular expression pattern:


RedirectMatch 301 /oldurl/(.*) http://www.example.com/newurl/$1


This will redirect any requests for /oldurl/somepage to http://www.example.com/newurl/somepage with a 301 redirect status.


Remember to test your redirects carefully to ensure they work as expected.