On Mon, 20 Jul 2015 03:06:30 -0700, apoorv.kanungo wrote:
> Thanks for the answer gordon I know we change individual page url with
> htaccess Apache file but I want it to be dynamic like if the user enter
> title of the page portfolio the page url should be /portfolio.
Are you referring to the url used to make the request, or the page
location shown in the browser after the request has been served?
The browser address bar will show the actual url fetched, which means you
need to have /pages/page.php?id=n redirect for each valid n (and don't
forget to trap invalid n) to something like /docs/portfolio, and then
process all requests for /docs/* in code that looks at the request header
and calculates which content to return (and again has a sensible default
if * doesn't match a valid value).
In apache, the configuration directive is:
AliasMatch ^/docs/.* /pages/page.php
AliasMatch ^/docs /pages/page.php
and then in /pages/page.php, you need to:
a) look at $_GET['id'] to see if there is an id value, test if it's
valid, and if it is redirect to /docs/portfolio (or whatever); or
b) If there's no $_GET['id'], look at $_SERVER['REQUEST_URI'] and see if
the uri matches /docs/portfolio (or whatever), and if it does, serve the
relevant page; or
c) send a default page because no valid data for a specific page request
was received.
Now a browser can request /pages/page.php?id=x and will get /docs/
documentname, where first of all /pages/page.php redirects to /docs/
documentname based on x, and then /pages/page.php serves content based on
documentname that appears from the uri /docs/documentname
The browser never realises that both requests are being served by the
same file, because the redirected uri is handled by the alias in the
server to point back at pages.php, the browser just follows the redirect
and asks the server for /docs/documentname
There may be other and better ways to do this, but I haven't found them
yet. I haven't looked very hard.
--
Denis McMahon,
denismf...@gmail.com