How to rewrite string in .htaccess?

by chasity.halvorson , in category: SEO , 7 months ago

How to rewrite string in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by ervin.williamson , 7 months ago


To rewrite a string in the .htaccess file, you can use the RewriteRule directive. Here is an example of the syntax to rewrite a string:

  1. Open your .htaccess file (located at the root directory of your website) in a text editor.
  2. Add the following line to rewrite the string:
RewriteEngine On
RewriteRule ^old-string$ /new-string [L,R=301]

Replace "old-string" with the string you want to rewrite, and "new-string" with the desired new string.

  1. Save the .htaccess file and upload it to your web server if necessary.

This code snippet will redirect any requests for the "old-string" to the "new-string" with a status code of 301 (permanent redirect). The "L" flag indicates that this is the last rule to be processed, and the "R" flag specifies that it is a redirect.

Make sure to test the redirection after making changes to ensure it is working as expected.