How to 301 redirect static URLs using htaccess

If your website has static URLs i.e. do not contain any query string parameters and you need to redirect your old website URLs to your new website URLs then you don’t have to fear anymore. You can write simple redirect statements in your .htaccess file and you don’t have to be regular expression guru.

Add the following line in your .htaccess file

redirect 301 /oldname http://www.example.com/newname 

As you can see in the above statement the htaccess tells the Apache web server to 301 redirect URL if it encounters /oldname to http://www.example.com/newname. You can add as many statements as you like however if there are over 20 plus URLs then consider using RedirectMatch. You should try your hand at regular expressions and get the job done in few statements.

Comments?

Leave a Reply

Your email address will not be published.