How to set url rewriting in .htaccess file?

Member

by lily , in category: Third Party Scripts , a month ago

How to set url rewriting in .htaccess file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dana , a month ago

@lily 

To set up URL rewriting in your .htaccess file, follow these steps:

  1. Create or edit your .htaccess file in the root directory of your website.
  2. Add the following code to enable URL rewriting:
1
2
RewriteEngine On
RewriteBase /


  1. To redirect a specific URL to a different page, use the following syntax:
1
RewriteRule ^old-url$ /new-url [L,R=301]


Replace "old-url" with the original URL and "new-url" with the desired URL to redirect to. The "[L,R=301]" flags indicate that it is the last rule and a permanent redirect.

  1. To rewrite a URL with query parameters, use the following syntax:
1
2
RewriteCond %{QUERY_STRING} param=value
RewriteRule ^example/$ /new-example/? [R=301,L]


Replace "param=value" with the query parameter and value to check for, "example" with the original URL, and "new-example" with the rewritten URL.

  1. Save your .htaccess file and test the new URL rewriting to ensure it is functioning correctly.