How can I mod_rewrite a query parameter to a path folder name?

by jacey.lubowitz , in category: SEO , a month ago

How can I mod_rewrite a query parameter to a path folder name?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by chasity.halvorson , a month ago

@jacey.lubowitz 

You can use mod_rewrite to rewrite a query parameter to a path folder name by using the following code in your .htaccess file:

1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]


This code will take the value of the "page" query parameter in the URL (e.g. www.example.com/?page=about) and rewrite it as a folder name in the URL (e.g. www.example.com/about/). Note that this code assumes that the file "index.php" is the one handling the page requests.