I've struggled with exactly what to search to find the answer to this question so I thought I would ask it instead.
I am building a small CMS script with PHP and want to prettify my urls. I have no issue with sending root level requests to my index.php
as variables; for example example.com/index.php?p=about-us
to example.com/about-us
. However, without removing this facility I want to redirect a request like example.com/blog/a-post
to example.com/blog.php?b=a-post
. How can I achieve this without it getting consumed by the original index rewrite?
I apologise if the terminology I have used to describe my problem is not quite right, it's been some time since I have done any coding and I feel rusty as hell!
--Edit--
The code I currently have is below:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
I wish the user to be able to access the url
url.com/blog/a-post
But I want this to actually access
url.com/blog.php?b=a-post