Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15605
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: change page url according to id |
| Date | 2015-07-21 22:04 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1473148.XobnLxc11U@PointedEars.de> (permalink) |
| References | <0bc4ef40-a643-427a-8971-0d5d9ed574d5@googlegroups.com> <WJednSeTUfllMDHInZ2dnUU7-I-dnZ2d@posted.internetamerica> <c9ebddf7-5d0a-4548-a0a2-8cef38d99ea3@googlegroups.com> <mok4r9$cqi$1@dont-email.me> <6rurx.288487$Pb6.182445@fx04.iad> |
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.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web