Get friendly URL and query database - .htaccess

I need to know what web server and server side framework will let me achieve the following:
I don't know is there is a technical name for this technique. So basically want to get any url in my domain and use it to query a database.
So for example, if I navigate to http://example.com/jack.htm, I want to do "select * from users where name like %jack%"
and then I want to return in the web page something like:
Our user's named Jack:
Jack Martins age 26
Jack Johnson age 32
etc..
Obviously we have a sql database with all user's names and age. Also jack.htm does not exist as a htm document in my web server, I need to generate it on the fly but not actually keep it forever.

Your webserver needs to rewrite the URL and turn the part before ".htm" into a parameter for an existing page that uses this parameter to query the database.
Eg. apache config
RewriteRule /\(.*\)\.htm$ /querydb.php?$1
I'v no experience with .htaccess, but something like:
RewriteRule ^\(.*\)\.htm$ /querydb.php?$1
Watch out for SQL injection inside querydb.php
jack.htm will never need to exist, and if it does, it won't be used.

Related

Azure cdn Ignore query strings purpose

I know what is the difference between Azure CDN query string modes and I have read a helpfull example of query string modes but...
I don't understand what is the purpose of "Ignore query strings" or how this can be useful in a real dynamic web.
For example, suppose we have a product purchase website with a URL similar to www.myweb.com/products?id=3
If we use "Ignore query strings"... Does this mean that if an user later requests product 4 (www.myweb.com/products?id=4), he will receive the page for product 3?
I think I'm not understanding correctly Azure CDN, I'm seeing Azure CDN as a dynamic content CDN, however Azure CDN is only used for static content as this article explains:
Standard content delivery network (CDN) capability includes the ability to cache files closer to end users to speed up delivery of static files.
This is correct? Any help or example on the subject is welcome
Yes, if you are selected Ignore query strings Query string caching behavior (this is the default), in your case subsequent requests after the initial request www.myweb.com/products?id=3, no matter the query string value, that POP server will serve the same content until it's cache period expires.
And for the second question, CDN is all about serving static files. To my understanding i believe what the article says is about dynamic site accelaration. It's about bunch of techniques to optimize dynamic web sites content serving performance. Because unlike static web sites, dynamic web sites assets (static files. ex: images, js, css, html) are loading dynamically based on the user behavior.
Now that I have it clearer, I will answer my question:
Azure CDN - Used to cache static content, even on dynamic web pages.
For the example in the question, all products must download the same javascript and css content, for those types of files Azure CDN is used. Real example using "Ignore query strings":
User A www.myweb.com/products?id=3, jquery-versionX.js and mystyles.css are not cached, the server is requested and the user receives it.
User B www.myweb.com/products?id=4, since we are using "Ignore query strings" the jquery-versionX.js and mystyles.css files are cached, they are served to the user without requesting it from the server again.
User C www.myweb.com/products?id=3, since we are using "Ignore query strings" the jquery-versionX.js and mystyles.css files are cached, they are served to the user without requesting it from the server again.
Reddis or other similar - Used to cache dynamic content (queries to databases for example).
For the example in the question, all the products have different information, which is obtained by doing a database query. We can store those queries or JSON objects in a Reddis cache. Real example:
User A www.myweb.com/products?id=3, product 3 is not cached, it is requested from the server and received by the user.
User B www.myweb.com/products?id=4, product 4 is not cached, it is requested from the server and received by the user.
User C www.myweb.com/products?id=3, product 3 is cached, the server is not requested and the user receives it from the cache.
Summary:
Both methods can be used simultaneously, Azure CDN is for static content and Reddis or similar for dynamic content.

Redirect to a specific link routing

i'm using express to make a electronic document management (EDMS) in node.js.
After the user login, I'll have a simple box, where he's chosee between two options:
a. search XML files
b. search Other Documents files
is there a way to create specific routing for, if he chooses to go only with XML, all links i'll be under that routing?
Something like xml/home/ and otherDocuments/home/ and the rest of the methods ill be xml/something and otherDocuments/something?

NodeJS 6.x Express 4.x PostgreSQL 9.x dynamic routes and dynamic views with dynamic SQL

I am new to Node.js 6 and Express 4. I am wondering if something like this is possible todo? It appears wildcards can be used in the routeing of node. Is it possible to have a database driven app that is dynamic with routes and views? What I mean is something like the following URL's
/ <- can be anything
/xyz
/15/abc/xyz
So node/express would hit the database for the URL of / and then dynamically take the values in the row for / lookup it found, and output the path to the view template page with the SQL query ready to be used in the view template file that is local on disk. I know their is no way to dynamically generate the html because the SQL will be different for each view template URL. So that would haft to be a hard file with template engine like handlebars, etc. It appears node/express can dynamically deal with routes on the fly so this should be possible todo I think.
So when node/express get the URL of /xyz it will go into the database look up the URL and then output the SQL in the lookup row and call the path to the view template for that row it found in the database. Database could be a json file not sql too. Do not know what would be faster since both would be in RAM.
I am wondering if anyone has ever tried this? If they have dose anything like this or dose anyone know of a boilerplate with this kind of a setup on github? I can see several problems.
Handling 404 errors
Database pools, Ways to reduce the open and closing sockets. So when 100 URL requests would not have a 1,000 open and close socket requests. It would have just 1 open socket request and do all the SQL via that socket. Or have 64 sockets for 64 cpu system. Not open and closing socket every time you hit the URL.
Run app under PM2 Clustering so it will use all the CPU's not just one CPU.
I would like any input. How you would over come the problems listed or boilerplate to something like this if it is out their already?
What you're describing is a RESTful API. Generally, the very first item in the URL path is static if you're serving webpages, since otherwise you wouldn't be able to serve anything else from the root path, such as -- like you noticed -- error pages. So you'll commonly see URLs like www.mystore.com/products/1234.
Your #2 and #3 have nothing to do with routing. Connection pools don't work how you think: it's about reusing and managing the lifespans of many connections, which are picked up and released by your app as needed. You don't want to be sending all your SQL over one socket (since a long-running query would halt everything else until it completed), and the number of open sockets isn't limited by how many CPUs you have.
Clustering is just as possible with a RESTful app as it is with a non-RESTful one.

How to get profile picture of user in Drupal from nodejs

In Drupal the profile image of user is stored as fid, and it can be retrieved in the Drupal php code base like this
file_create_url(file_load($user->picture)->uri)
where $user->picture is the fid and is retrievable from database directly in nodejs
But is it possible do the fid to file location conversion in nodejs so that the nodejs app can just read the fid from drupal database and find the file.
Thanks for help in advance,
Jib
Probably not without re-implementing a lot of Drupal functionality. You can follow the trail of function calls back from file_load and file_create_url and you'll see what I mean.
Being that you probably can retrieve the filename from the FID in the database, one option is making an assumption on the path using the retrieved filename. For example, a MySQL query along the lines of 'SELECT filename FROM file_managed WHERE fid = ' + fid and a URL assumption like '/sites/default/files/image_style/' + filename
Another likely less desirable option is creating a simple API endpoint or PHP script with Drupal bootstrap that returns the path. I say this is less desirable because you then have to make an HTTP request to Drupal and incur the overhead and latency associated with this request.

cross domain relation

suppose I have www.usa.com as main site. I will create www.utah.com..www.indiana.com...etc on same dedicated server with same hosting. After creating those usa-state sites I will register users from www.usa.com and place them under different states and will give them their own site like www.utah.com/andy . Here user Andy was registered from www.usa.com but placed under www.utah.com. If I search user Andy from www.utah.com or www.usa.com i can get his details but i cant get his details from www.indiana.com.
how i can achieve the above like registered from one site but placed in another site? do u recommend one database-multiple domain concept? how should i approach to built this type of application? pls help
From your description it sounds more like your application (as a single app) would be logically organized like this:
usa.com
usa.com/utah
usa.com/utah/andy
usa.com/indiana
...
You could use separate domains for the states through some URL rewriting to achieve what you want. Your application would handle the search logic.
-OR-
The alternative is to setup each site as it's own application. The usa site would just be configured to search each of the state sites (via a query string maybe) and aggregate the results.
I know there are other ways to setup what you are looking for but I think these are probably the two major alternatives.

Resources