0

Appreciate the help in advance because I absolutely hate mod_rewrite and can't get my head around it!

I currently have a rule in my .htaccess that converts two parameters in a query string to a pretty URL.

RewriteRule ^projects/([^/]+)/([^/]+)/?$ single-project.php?id=$1&section=$2 [L]

For example, this converts the URL /single-project.php?id=5&section=documents into /projects/5/documents/

What I want to do is have an additional query string (through a new rule) that would convert /projects/5/documents/?subfolder=PDFs into /projects/5/documents/PDFs/

A few caveats:

  • This additional query string may not always be there
  • This query string would only need to work if the URL is /projects/[ANY_ID]/documents/

I hope this makes sense and that you can help!

Cheers

1 Answer 1

2

With your shown samples, please try following rules in your .htaccess file. Please make sure to clear your browser cache before testing URLs. Have added comments inside rule file for understanding.

RewriteEngine ON
##Op's already present rules, added 1 more flag in it QSA.
RewriteRule ^projects/([^/]+)/([^/]+)/?$ single-project.php?id=$1&section=$2 [NC,QSA,L]
##Newly added Rule to perform internal rewrite for project id here.
RewriteRule ^(projects)/([^/]+)/([^/]+)/(.*)/?$ $1/$2/$3/?subfolder=$4 [NC,QSA,L]
Sign up to request clarification or add additional context in comments.

2 Comments

That's sorted it, I think. Thank you so much!
@DanielKilburn, your welcome, cheers and happy learning.

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.