How to create friendly url using .htaccess?

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

How to create friendly url using .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 23 days ago

@jasen_gottlieb 

To create a friendly URL using .htaccess, you can use the mod_rewrite module. Here is an example of how you can rewrite a URL:

  1. Create a file named .htaccess in the root directory of your website.
  2. Add the following code to your .htaccess file:
1
2
RewriteEngine On
RewriteRule ^friendly-url$ original-url [L]


In this code, "friendly-url" is the URL that you want to display in the browser, and "original-url" is the actual URL of the page. The [L] flag signifies that this is the last rule to be processed.

  1. Save the .htaccess file and upload it to the root directory of your website.
  2. Test the new URL in your browser to make sure it is redirecting correctly.


By using mod_rewrite in your .htaccess file, you can create user-friendly URLs that are easier to read and understand.