PHP Dynamic URL Parameters and GET

Viewed 142

I'd like to ask if it's possible to use a dynamic url and GET at the same time.

Let's say my current dynamic url is:
https://yourdomain.com/blog/this-is-a-title

Would it be possible to make this work too:
https://yourdomain.com/blog/this-is-a-title?action=delete

RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?id=$1

The dynamic url mentioned first works fine, but I want to make the second work as well.
This is my .htaccess - hope it helps.

PS: I know that the regex in my htaccess isn't correct, it's just an example.

1 Answers

Have your .htaccess Rules file in following manner. Please make sure that your htaccess Rules file is present in root folder(where blog and htaccess both are residing in it; htaccess shiouldn't be inside blog folder; should be place same folder with it). Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Newly added rules here...
RewriteBase /blog/
RewriteCond %{THE_REQUEST} \s/blog/(?:[^?]*)?action=(\S+)\s [NC]
RewriteRule ^ index.php?action=%1 [L]

##Old Rules OP's htaccess ones.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?id=$1
Related