Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15591 > unrolled thread

change page url according to id

Started byadam <apoorv.kanungo@gmail.com>
First post2015-07-19 23:08 -0700
Last post2015-07-24 08:28 +0200
Articles 12 — 9 participants

Back to article view | Back to comp.lang.php


Contents

  change page url according to id adam <apoorv.kanungo@gmail.com> - 2015-07-19 23:08 -0700
    Re: change page url according to id gordonb.dc822@burditt.org (Gordon Burditt) - 2015-07-20 03:14 -0500
      Re: change page url according to id apoorv.kanungo@gmail.com - 2015-07-20 03:06 -0700
        Re: change page url according to id Richard Damon <Richard@Damon-Family.org> - 2015-07-20 08:29 -0400
        Re: change page url according to id Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-21 00:47 +0000
          Re: change page url according to id Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-07-21 12:28 -0400
            Re: change page url according to id Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 22:04 +0200
              Re: change page url according to id apoorv.kanungo@gmail.com - 2015-07-22 06:10 -0700
                Re: change page url according to id gordonb.8ssp0@burditt.org (Gordon Burditt) - 2015-07-22 17:34 -0500
                Re: change page url according to id "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-07-23 01:12 +0200
                Re: change page url according to id Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-22 23:45 +0000
                  Re: change page url according to id Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-24 08:28 +0200

#15591 — change page url according to id

Fromadam <apoorv.kanungo@gmail.com>
Date2015-07-19 23:08 -0700
Subjectchange page url according to id
Message-ID<0bc4ef40-a643-427a-8971-0d5d9ed574d5@googlegroups.com>
hello there I have a application where admin enter page title and description and enter and that value goes in to database and then I retrieve that value and show that in the page.

Now the problem I have is that page have a url like /page.php?id=51 but I want it to be like /contact us or /about us.

wordpress has a same sysem it has a page.php and it is a default template for pages and every page has different tile.    

[toc] | [next] | [standalone]


#15592

Fromgordonb.dc822@burditt.org (Gordon Burditt)
Date2015-07-20 03:14 -0500
Message-ID<WJednSeTUfllMDHInZ2dnUU7-I-dnZ2d@posted.internetamerica>
In reply to#15591
> hello there I have a application where admin enter page title and
> description and enter and that value goes in to database and then
> I retrieve that value and show that in the page.

> Now the problem I have is that page have a url like /page.php?id=51
> but I want it to be like /contact us or /about us.

> wordpress has a same sysem it has a page.php and it is a default
> template for pages and every page has different tile.

Web servers like Apache tend to have some configuration directives
that allow you to manipulate URLs before they are processed.  For
example, you could alias /contact_us to /page.php?id=51 .

Another possibility is to alias anything under /document/ ...
to be handled by a particular CGI (which could be a PGP page).
The PGP page could look at the tail of the URL as well as
the other parts of it, and do what was needed to simulate
a whole tree of pages.  For example, it could look up the tail
of the URL (not including the variables) in a database and
use the information there to construct the page.

A number of genealogy websites pretend to have a large
tree of URLs like:

	http://genealogy.example.com/genealogy/person_page/39273
	http://genealogy.example.com/genealogy/family_page/22612

which actually have one or a small number of CGIs handling
anything under http://genealogy.example.com/genealogy/ .
It can also handle multiple site names which refer to independent
genealogy trees.  The links intentially follow the forms above,
rather than a bunch of variables passed to the database.

[toc] | [prev] | [next] | [standalone]


#15593

Fromapoorv.kanungo@gmail.com
Date2015-07-20 03:06 -0700
Message-ID<c9ebddf7-5d0a-4548-a0a2-8cef38d99ea3@googlegroups.com>
In reply to#15592
On Monday, July 20, 2015 at 1:44:56 PM UTC+5:30, Gordon Burditt wrote:
> > hello there I have a application where admin enter page title and
> > description and enter and that value goes in to database and then
> > I retrieve that value and show that in the page.
> 
> > Now the problem I have is that page have a url like /page.php?id=51
> > but I want it to be like /contact us or /about us.
> 
> > wordpress has a same sysem it has a page.php and it is a default
> > template for pages and every page has different tile.
> 
> Web servers like Apache tend to have some configuration directives
> that allow you to manipulate URLs before they are processed.  For
> example, you could alias /contact_us to /page.php?id=51 .
> 
> Another possibility is to alias anything under /document/ ...
> to be handled by a particular CGI (which could be a PGP page).
> The PGP page could look at the tail of the URL as well as
> the other parts of it, and do what was needed to simulate
> a whole tree of pages.  For example, it could look up the tail
> of the URL (not including the variables) in a database and
> use the information there to construct the page.
> 
> A number of genealogy websites pretend to have a large
> tree of URLs like:
> 
> 	http://genealogy.example.com/genealogy/person_page/39273
> 	http://genealogy.example.com/genealogy/family_page/22612
> 
> which actually have one or a small number of CGIs handling
> anything under http://genealogy.example.com/genealogy/ .
> It can also handle multiple site names which refer to independent
> genealogy trees.  The links intentially follow the forms above,
> rather than a bunch of variables passed to the database.


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.   

[toc] | [prev] | [next] | [standalone]


#15594

FromRichard Damon <Richard@Damon-Family.org>
Date2015-07-20 08:29 -0400
Message-ID<sQ5rx.188973$RR7.130218@fx13.iad>
In reply to#15593
On 7/20/15 6:06 AM, apoorv.kanungo@gmail.com 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.>

The two ways I have seen this done is to use rewrite to map ALL (or a large set) of URLS to all map to something like index.php, and index.php check the URL it was called by to figure out what page to display (checking the mapping in the database).

A second way is to trap the 404 error and have that handler do this sort of operation.

The first is a bit faster, but a bit harder to have pages that bypass this mapping (if you want special code to process that page). The second handles this automatically, but does make the web server do a bit more work to redirect to the 404 error page.

[toc] | [prev] | [next] | [standalone]


#15597

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-07-21 00:47 +0000
Message-ID<mok4r9$cqi$1@dont-email.me>
In reply to#15593
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, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#15604

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-07-21 12:28 -0400
Message-ID<6rurx.288487$Pb6.182445@fx04.iad>
In reply to#15597
On Monday July 20 2015 20:47, in comp.lang.php, "Denis McMahon"
<denismfmcmahon@gmail.com> wrote:

> 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
> 
[snip]
> There may be other and better ways to do this, but I haven't found them
> yet. I haven't looked very hard.

The Apache's mod_alias[1] and mod_rewrite[2] modules will also do this

Assuming that the request URL is something like
  http://some.example.com/portfolio

then the mod_alias rule might look like
  RedirectMatch "^/portfolio" "/page.php?name=portfolio"

or the mod_rewrite rule might look like
  RewriteRule "^/portfolio" "/page.php?name=portfolio"

[1] http://httpd.apache.org/docs/2.4/mod/mod_alias.html

[2] http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
    http://httpd.apache.org/docs/2.4/rewrite/remapping.html

HTH
-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#15605

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-07-21 22:04 +0200
Message-ID<1473148.XobnLxc11U@PointedEars.de>
In reply to#15604
Lew Pitcher wrote:

> On Monday July 20 2015 20:47, in comp.lang.php, "Denis McMahon"
> <denismfmcmahon@gmail.com> wrote:
>> 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
>> 
> [snip]
>> There may be other and better ways to do this, but I haven't found them
>> yet. I haven't looked very hard.
> 
> The Apache's mod_alias[1] and mod_rewrite[2] modules will also do this
> 
> Assuming that the request URL is something like
>   http://some.example.com/portfolio
> 
> then the mod_alias rule might look like
>   RedirectMatch "^/portfolio" "/page.php?name=portfolio"

This will *redirect* everything starting with “portfolio”.  It can be 
simplified to, thereby improved (unless you really want to redirect 
everything, which is doubtful) to

  Redirect "/portfolio" "/page.php?name=portfolio"

mod_redirect, _not_ mod_alias, is the proper way here because with mod_alias 
you map URL-references to the *server’s filesystem* instead (possibly 
*above* the DOCUMENT_ROOT), and hopefully there is not going to be a 
publicly accessible *directory* with the path “/pages”:

<http://httpd.apache.org/docs/2.4/mod/mod_alias.html>

> or the mod_rewrite rule might look like
>   RewriteRule "^/portfolio" "/page.php?name=portfolio"

This will *rewrite* *everything* starting with “portfolio” *and* continue; 
for it to be equivalent to the above, it has to be

  RewriteRule "^/portfolio" "/page.php?name=portfolio" [redirect,last]

But firstly, not redirecting is better in this case because then the URI 
remains type-agnostic (so you should remove “redirect” and keep “last”), and 
secondly the problem described above remains.  Something like

  RewriteRule "^/portfolio/?$" "/page.php?name=portfolio&%{QUERY_STRING}" 
[noescape,last]

could work (watch for word-wrap).

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#15606

Fromapoorv.kanungo@gmail.com
Date2015-07-22 06:10 -0700
Message-ID<fd692e5f-69bb-42bd-bacf-c875a879c5e7@googlegroups.com>
In reply to#15605
On Wednesday, July 22, 2015 at 1:38:32 AM UTC+5:30, Thomas 'PointedEars' Lahn wrote:
> Lew Pitcher wrote:
> 
> > On Monday July 20 2015 20:47, in comp.lang.php, "Denis McMahon"
> > <denismfmcmahon@gmail.com> wrote:
> >> 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
> >> 
> > [snip]
> >> There may be other and better ways to do this, but I haven't found them
> >> yet. I haven't looked very hard.
> > 
> > The Apache's mod_alias[1] and mod_rewrite[2] modules will also do this
> > 
> > Assuming that the request URL is something like
> >   http://some.example.com/portfolio
> > 
> > then the mod_alias rule might look like
> >   RedirectMatch "^/portfolio" "/page.php?name=portfolio"
> 
> This will *redirect* everything starting with "portfolio".  It can be 
> simplified to, thereby improved (unless you really want to redirect 
> everything, which is doubtful) to
> 
>   Redirect "/portfolio" "/page.php?name=portfolio"
> 
> mod_redirect, _not_ mod_alias, is the proper way here because with mod_alias 
> you map URL-references to the *server's filesystem* instead (possibly 
> *above* the DOCUMENT_ROOT), and hopefully there is not going to be a 
> publicly accessible *directory* with the path "/pages":
> 
> <http://httpd.apache.org/docs/2.4/mod/mod_alias.html>
> 
> > or the mod_rewrite rule might look like
> >   RewriteRule "^/portfolio" "/page.php?name=portfolio"
> 
> This will *rewrite* *everything* starting with "portfolio" *and* continue; 
> for it to be equivalent to the above, it has to be
> 
>   RewriteRule "^/portfolio" "/page.php?name=portfolio" [redirect,last]
> 
> But firstly, not redirecting is better in this case because then the URI 
> remains type-agnostic (so you should remove "redirect" and keep "last"), and 
> secondly the problem described above remains.  Something like
> 
>   RewriteRule "^/portfolio/?$" "/page.php?name=portfolio&%{QUERY_STRING}" 
> [noescape,last]
> 
> could work (watch for word-wrap).
> 
> -- 
> PointedEars
> Zend Certified PHP Engineer
> Twitter: @PointedEars2
> Please do not cc me. / Bitte keine Kopien per E-Mail.

Guys I am sorry if I did not put my question correctly I know we can do that with htaccess but I have to manually enter redirect code in the htaccess.

I want it to be dynamic so that if user enter title of the page contact us the url in the browser will be example.com/contact us.

kind of like wordpress where it does not have multiple pages but one default template and url and title of all the pages are different.

can we do that with $_SERVER['REQUEST_URI'] 

[toc] | [prev] | [next] | [standalone]


#15607

Fromgordonb.8ssp0@burditt.org (Gordon Burditt)
Date2015-07-22 17:34 -0500
Message-ID<q9CdnVL9J_X3hy3InZ2dnUU7-N-dnZ2d@posted.internetamerica>
In reply to#15606
> Guys I am sorry if I did not put my question correctly I know we
> can do that with htaccess but I have to manually enter redirect
> code in the htaccess.

1.  Put in a directive manually to redirect an entire directory (and
    everything under it) to a PHP script.  Redirecting the entire
    site is a little tricky (where do you put the script, which you
    DO NOT want to redirect?).

    If you can figure out how to do it, you might try to redirect
    everything EXCEPT URLs begining with /page  .

2.  Write the PHP script so it uses $_SERVER['REQUEST_URI'] to look
    up the tail end of the URI (with variables taken off), in a 
    database, and use the resulting information to generate a page.
    If there is no information on the page entered, generate an
    error page.


> I want it to be dynamic so that if user enter title of the page
> contact us the url in the browser will be example.com/contact us.

This information needs to go in a database - what some user entered
somewhere in the past won't be remembered otherwise.

> kind of like wordpress where it does not have multiple pages but
> one default template and url and title of all the pages are different.

> can we do that with $_SERVER['REQUEST_URI']

That's one part of the solution.

[toc] | [prev] | [next] | [standalone]


#15608

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-07-23 01:12 +0200
Message-ID<mop80k$thd$1@solani.org>
In reply to#15606
apoorv.kanungo@gmail.com wrote:

> Guys I am sorry if I did not put my question correctly I know we can
> do that with htaccess but I have to manually enter redirect code in
> the htaccess.
> 
> I want it to be dynamic so that if user enter title of the page
> contact us the url in the browser will be example.com/contact us.
> 
> kind of like wordpress where it does not have multiple pages but one
> default template and url and title of all the pages are different.
> 
> can we do that with $_SERVER['REQUEST_URI']

I suggest you have a look at the CGI variable `PATH_INFO`, which is
supposed to be available in PHP via `$_SERVER['PATH_INFO']`.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#15609

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-07-22 23:45 +0000
Message-ID<mop9uu$jp8$1@dont-email.me>
In reply to#15606
On Wed, 22 Jul 2015 06:10:05 -0700, apoorv.kanungo wrote:

> Guys I am sorry if I did not put my question correctly I know we can do
> that with htaccess but I have to manually enter redirect code in the
> htaccess.
> 
> I want it to be dynamic so that if user enter title of the page contact
> us the url in the browser will be example.com/contact us.
> 
> kind of like wordpress where it does not have multiple pages but one
> default template and url and title of all the pages are different.
> 
> can we do that with $_SERVER['REQUEST_URI']

I thought I answered this already!

You set up your htaccess so that everything goes to a php page.

In the php page, you look at the server request variable and use that to 
calculate which content to deliver.

The url shown in the browser address bar will be the url that it 
requested. If you wish to change this, you need to use a redirect to the 
url that wish to have displayed. You can do this in the same php page.

In apache, at the host level, use:

AliasMatch ^/.* /index.php

Then every request will get passed to /index.php.

In /index.php, you can look at any request data (post or get) as well as 
the request uri, and then decide to do one of the following:

(a) Display content relevant to the request uri; or
(b) Issue a redirect header from the php to change the request uri; or
(c) Display default content

So then a request for http:/blah.blah.blah/blah?id=15 can trigger a 
redirect to http:/blah.blah.blah/documents (because your php knows that 
id 15 is documents), and http:/blah.blah.blah/documents gets processed 
according to the request uri and the documents content is delivered to 
the visitors browser.

Note that whether you do the redirections and processing in apache or php, 
there is a need to first of all create and then manage mappings of (a) id 
to content name and (b) content name to content source.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#15610

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-07-24 08:28 +0200
Message-ID<8461971.mpfdkj3dN5@PointedEars.de>
In reply to#15609
Denis McMahon wrote:

> In apache, at the host level, use:
> 
> AliasMatch ^/.* /index.php
> 
> Then every request will get passed to /index.php.

To a *file* named “index.php” located *in the root directory
of the filesystem*.  _Not_ in the Web root.  A file that
most certainly does not and in any case SHOULD NOT exist.
A file that in a default configuration *for good reasons*
cannot be accessed:

---------------------------------------------------------
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
  Options FollowSymLinks
  AllowOverride None
  Require all denied
</Directory>
---------------------------------------------------------

RTFM.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web