I want the following functionality for a site I'm working on:
I want to be able to dynamically serve up content according to the request url.
So lets say the url is
http://www.siteurl.co/category1/requestParam1reqeuestParam2
I would want to display content from category1 with requestParam1 and requestParam2 parameters, if category1 exists and the request params are valid. If no category1 is present in my database for example I would want to display some default page.
This is how far I got so far: I can add something like the following to .htaccess file. This will redirect requests to any url on my site to the home page:
RewriteEngine On
RewriteRule ^.+$ / [R=302,NC,L]
I would then need to get the requested(perhaps the referer) url with javascript. Parse it and serve up appropriate content according to that url.
The biggest problem with this now, is that the above code in htaccess will change the url in the browser address bar to that of the default content page. But I'd want the url in the browser address bar to stay the same after the content page is loaded. I'm also not sure how to get the requested url with javascript.
There must be a clean way of doing this. I just can't seem to find the right keywords to search for
I think you're looking for a server side framework to generate the content based on the URL. What you've done is just told the server to redirect to another page, but all that's doing is delivering a completely new web page (one with the URL you've specified).
You should read up on what server side frameworks are and how they work. You'll find that you won't want to explicitly redirect your page requests, and you'll do things in the framework to handle extracting parameters out of the URL to generate the dynamic content and then return that content to the browser.
Here's a link to get you started...
https://developer.mozilla.org/en-US/docs/Learn/Server-side/First_steps/Web_frameworks
Good luck!