How to use $_get parameter to make seo friendly urls?

by cameron_walter , in category: SEO , a year ago

How to use $_get parameter to make seo friendly urls?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by susan , a year ago

@cameron_walter 

To use the $_GET parameter to create SEO-friendly URLs, follow these steps:

  1. 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.
  2. Create a .htaccess file in your website's root directory (if it doesn't already exist).
  3. 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]


  1. In your PHP script (e.g., index.php), retrieve the requested URL using the $_GET variable:
1
$url = $_GET['url'];


  1. 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.
  2. 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.