2

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.

4
  • So you want to hit url https://yourdomain.com/blog/this-is-a-title in browser and change it in browser to https://yourdomain.com/blog/this-is-a-title?action=delete please confirm once? Commented Jun 20, 2021 at 18:21
  • @RavinderSingh13 no. I want to display the blog at https://yourdomain.com/blog/this-is-a-title but if it has the parameter ?action=delete I want the user to see a different page (but it's still on the same page) - Let me know if you still didn't understand! Commented Jun 20, 2021 at 18:27
  • Let me re-confirm that we are on same page or not. You want URL https://yourdomain.com/blog/this-is-a-title?action=delete to be served by index.php is this right? If yes then what parameters it should pass to index.php file? eg: index.php?delete? Commented Jun 20, 2021 at 18:28
  • We're always on the same page - page doesn't change! index.php : yourdomain.com/blog/this-is-a-title index.php?action=delete : yourdomain.com/blog/this-is-a-title?action=delete Commented Jun 20, 2021 at 18:31

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.