Could someone please double check this working code for me. I no very little about rewrites but through testing and reading through this forum I came up with this, so I just want to make sure the code is secure and optimized.
What you need is a good specification, i.e., redirect speedbump.php (in the site’s root directory) to section/category/speedbump.php retaining the query string.
The FIRST thing you need to do (with the query string) is recognize that you are using reserved characters so your query string should NOT be accepted by browsers/servers:
Once you’ve stripped the http:// away from the value in your query string (there is NO need to send that, is there?), all you need is:
RewriteEngine on
RewriteRule ^speedbump\\.php section/category/speedbump.php [L]
BECAUSE the query string is handled separately and will be sent along with the redirection.
Thanks for the assist DK – love your posts, great teacher.
Sorry I didn’t get back to you sooner, but I got sidetracked and didn’t receive an email notice about this thread.
Anyway, I was trying to be smart with the URL using section and category but I should have mentioned that section could be Weblinks or About and category could be Links or News like so:
The sections and categories can vary, so the speedbump needs to work under different scenarios, that is why I thought using query string was the right way to go.
Now using your solution, section and category would have to be static right? So as it is, that wouldn’t work for me?
So is using query string the best solution under these conditions and should ^url= be open ended or is there a regex that should be used?
Okay, sections can be Weblinks or About and category can be Links or News. However, your stated problem (specification) was to merely remove the section and category from the URI. If you do need those, we need to work on the specification first:
Do the values you use for section and category get translated to something in the redirection? If not, don’t worry about it, you can always use the {THE_REQUEST} value to fetch the original URI.
If you DO need the values, it’s easy to have mod_rewrite match the pairs of options (or get the values for a query string) but you left that undefined.
Actually, using “my solution,” the contents of the section and category were irrelevant and were simply discarded.