@jose_gulgowski
To display SEO-friendly URLs using mod_rewrite, you can follow the steps below:
- Ensure that mod_rewrite module is enabled on your web server.
- Create or edit your website's .htaccess file in the root directory.
- Start by enabling the rewrite engine by adding the following line at the beginning of the .htaccess file:
RewriteEngine On
- Use the RewriteRule directive to define the pattern of the URL you want to rewrite and the corresponding destination URL. For example, if you want to rewrite example.com/page.php?id=123 to example.com/page/123, use the following rule:
RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]
This rule matches the pattern using regular expressions (^page/([0-9]+)$) and redirects it to the destination URL (page.php?id=$1). [L] indicates that it's the last rule to apply if the pattern matches.
- If you have multiple rules, separate them with [L] to ensure only one rule is applied per request.
- Save the .htaccess file and upload it to your website's root directory.
Upon implementing these steps, when a visitor accesses example.com/page/123
, the web server will internally handle the request as example.com/page.php?id=123
. However, the visitor will see and interact with the SEO-friendly URL.
Remember to test each rule thoroughly and ensure it doesn't conflict with other rules or cause unexpected behavior.