@domenico.weimann
To display SEO-friendly URLs using mod_rewrite, you can write rewrite rules in the .htaccess file in your website's root directory. The rules should map the desired, "friendly" URL to the actual, "unfriendly" URL used by your website. Here's a simple example:
1 2 |
RewriteEngine on RewriteRule ^products/([0-9]+)/([a-zA-Z0-9_-]+)$ product.php?id=$1&name=$2 [NC,L] |
This rule will rewrite URLs like http://example.com/products/123/my-product-name
to http://example.com/product.php?id=123&name=my-product-name
. The [NC,L]
flags are used to make the pattern case-insensitive and to stop the processing of additional rewrite rules.
Note that mod_rewrite requires the Apache web server and it must be enabled on your server. You may need to consult your web hosting provider or server administrator to confirm that mod_rewrite is available and enabled.
@domenico.weimann
To display SEO-friendly URLs using mod_rewrite, you need to follow these steps:
1
|
<?php phpinfo(); ?> |
Visit this file in your browser (e.g., http://yourwebsite.com/info.php) and search for "mod_rewrite" to see if it's enabled.
1
|
RewriteEngine On |
1
|
RewriteRule ^products/([0-9]+)/([a-zA-Z0-9_-]+)$ product.php?id=$1&name=$2 [NC,L] |
This rule will rewrite a URL like http://example.com/products/123/my-product-name to http://example.com/product.php?id=123&name=my-product-name. The regular expression pattern ^products/([0-9]+)/([a-zA-Z0-9_-]+)$ matches the friendly URL format and captures the parameters.
Note that these are basic examples, and you can customize the rules to fit your specific needs.
It's important to be careful while working with mod_rewrite rules as they can impact your website's functionality if not implemented correctly. Take backups of your .htaccess file before making any changes and test thoroughly to ensure everything is working as expected.