0

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
Benjy
  • 1
  • 2
  • "How can I achieve this without it getting consumed by the original index rewrite?" - the order is important. If you post the code you have tried and the specific problem you are having then it would be easier to answer. "for example `example.com/index.php?p=about-us` to `example.com/about-us`" - don't you mean the other way round? – MrWhite Sep 19 '16 at 21:55
  • Sorry, you're right I did not phrase this as clearly as I really should have done! I will edit my original post above to include the code I currently have. – Benjy Sep 21 '16 at 17:15

1 Answers1

0
RewriteEngine On
RewriteRule ^work(.*)/([^/]*) work-single.php$1?slug=$2 [QSA]

work is the pseudo folder and work-single.php is the file which is getting the request of the variable

thedudecodes
  • 101
  • 1