@cameron_walter
To use the $_GET parameter to create SEO-friendly URLs, follow these steps:
- Enable the rewrite engine in your web server (e.g., Apache). This allows you to rewrite URLs and redirect them to a specific script or page.
- Create a .htaccess file in your website's root directory (if it doesn't already exist).
- Write the following rules in your .htaccess file to redirect all requests to a specific script (e.g., index.php), with the requested URL passed as a query parameter:
1
2
3
4
|
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
|
- In your PHP script (e.g., index.php), retrieve the requested URL using the $_GET variable:
- Perform any necessary processing or redirection based on the captured URL. For example, you can parse the URL to extract parameters and query a database accordingly.
- Display the corresponding content based on the captured URL.
By implementing these steps, you can create SEO-friendly URLs that are more readable by both search engines and users. For example, instead of using a URL like example.com/index.php?url=products&category=electronics
, you can have example.com/products/electronics
, which is much more user-friendly and beneficial for SEO purposes.