 |
|
 |
|
Next: Popup Images
|
| Author |
Message |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 1) Posted: Wed Mar 10, 2004 7:40 pm
Post subject: Mod_rewrite for PHP template Archived from groups: freeserve>webspace>authoring, others (more info?)
|
|
|
An Apache question - I've had a look on the ALA articles regarding
friendly URLs, and also the Apache manuals, but I'm not quite sure where
I need to be heading:
The current setup is at www.rossmore.org/clubs/ - As you can see, each
club (albeit missing content on the pages) is situated in their own
folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
Having gotten into using a database with PHP recently, my aim is to
create a single template (that would be at /club/index.php) and have it
pull the club info (time, day, who, where etc) out of a database and
populate it. I can forsee that this would lead to URLs such as
/clubs/index.php?id=12 where id 12 tells the db to enter all the info
for table tennis, say.
What I'd like, is for me to be able to link pages, *and users to be able
to type in page addresses*, as they previously were, but the backend of
the site to know, for instance, that /clubs/tabletennis/ actually means
/clubs/index.php?id=12.
From what I've read, it's mod_rewrite that I need. Closest I came up
with is:
RewriteEngine On
RewriteBase /
RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
....but this didn't seem to work. Any ideas?
Also, is there a way of using regular expressions, or adding a further
column in the database so that I don't have a whole list of
RewriteRules, but one containing a RE instead?
Thanks for your time.
--
Gazza
http://www.rossmore.org/
http://www.garyjones.co.uk/
"Some people don't listen, they simply wait to speak" >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 411
|
(Msg. 2) Posted: Wed Mar 10, 2004 8:11 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gazza wrote:
> The current setup is at <a style='text-decoration: underline;' href="http://www.rossmore.org/clubs/" target="_blank">www.rossmore.org/clubs/</a> - As you can see, each
> club (albeit missing content on the pages) is situated in their own
> folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
>
> Having gotten into using a database with PHP recently, my aim is to
> create a single template (that would be at /club/index.php) and have it
> pull the club info (time, day, who, where etc) out of a database and
> populate it. I can forsee that this would lead to URLs such as
> /clubs/index.php?id=12 where id 12 tells the db to enter all the info
> for table tennis, say.
>
> What I'd like, is for me to be able to link pages, *and users to be able
> to type in page addresses*, as they previously were, but the backend of
> the site to know, for instance, that /clubs/tabletennis/ actually means
> /clubs/index.php?id=12.
>
> RewriteEngine On
> RewriteBase /
> RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
> ...but this didn't seem to work. Any ideas?
RewriteRule ^clubs/tabletennis clubs/index.php?id=12 [L,QSA]
If you have a .htaccess file in the site's doc_root, check to be sure
that AllowOverride is set so your .htaccess file will work. You can also
set the mod_rewrite logging options so you can see what is happening
with your rules if you continue to have problems.
> Also, is there a way of using regular expressions,
The RewriteRule is a regex. So if you had database ids like
'tabletennis', 'art','football8', etc. you could use something like:
RewriteRule ^clubs/([^/]+)/?$ clubs/index.php?id=$1 [L,QSA]
Which would make links like:
domain.tld/clubs/tabletennis/
domain.tld/clubs/art/
domain.tld/clubs/football8/
call these:
domain.tld/clubs/index.php?id=tabletennis
domain.tld/clubs/index.php?id=art
domain.tld/clubs/index.php?id=football8
HTH
--
Justin Koivisto - spam.DeleteThis@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
SEO Competition League: <a style='text-decoration: underline;' href="http://seo.koivi.com/" target="_blank">http://seo.koivi.com/</a><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2004 Posts: 96
|
(Msg. 3) Posted: Wed Mar 10, 2004 8:16 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gazza <gary.DeleteThis@garyjones.co.uk.invalid> wrote in
news:MPG.1ab955374f2e2d00989697@news.ntlworld.com:
> An Apache question - I've had a look on the ALA articles regarding
> friendly URLs, and also the Apache manuals, but I'm not quite sure
where
> I need to be heading:
>
> The current setup is at <a style='text-decoration: underline;' href="http://www.rossmore.org/clubs/" target="_blank">www.rossmore.org/clubs/</a> - As you can see, each
> club (albeit missing content on the pages) is situated in their own
> folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
>
> Having gotten into using a database with PHP recently, my aim is to
> create a single template (that would be at /club/index.php) and have
it
> pull the club info (time, day, who, where etc) out of a database and
> populate it. I can forsee that this would lead to URLs such as
> /clubs/index.php?id=12 where id 12 tells the db to enter all the info
> for table tennis, say.
>
> What I'd like, is for me to be able to link pages, *and users to be
able
> to type in page addresses*, as they previously were, but the backend
of
> the site to know, for instance, that /clubs/tabletennis/ actually
means
> /clubs/index.php?id=12.
>
> From what I've read, it's mod_rewrite that I need. Closest I came up
> with is:
> RewriteEngine On
> RewriteBase /
> RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
> ...but this didn't seem to work. Any ideas?
> Also, is there a way of using regular expressions, or adding a further
> column in the database so that I don't have a whole list of
> RewriteRules, but one containing a RE instead?
>
> Thanks for your time.
>
I use the following for the redesign of my site that is underway.
The following are snips of the core logic.
The full code I'm using is still under development and I will eventually
release under GPL. I'm slowly adding more features like smarty template
integration, database abstruction layer, etc., and building a web
interface. It is going to use objects for all page components and make
it easy to change page layout as well as the ordering of objects. I
know there are many content management systems already available, but
I'm developing for my own use for the exact behavior that I prefer. If
nobody else uses it, that is ok.
-----.htaccess-----
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /index.php?$1
----------
-----index.php-----
//Strip leading and trailing slashes from $request_uri
$request_uri = $_SERVER["REQUEST_URI"];
if (substr($request_uri,-1) == "/") {
$request_uri = substr($request_uri,1,-1);
} else {
$request_uri = substr($request_uri,1);
}
//Split $request_uri into component variables
if (strlen($request_uri)>0) {
$request_vars = split("/",$request_uri);
} else {
$request_vars[0] = "index";
}
//Page to display
$page = $request_vars[0];
//Values to pass to displayed page
for($i = 0; $i < count($request_vars); $i++) {
request_vars[$i] = $request_vars[$i];
//echo "request_vars[$i] = ".$request_vars[$i]."<br />";
}
----------
Basically, is works as follows:
1) .htaccess uses mod_rewrite to pass requested URI to index.php
2) index.php parses the values in the URI (separated by slashes)
assuming that the first value is the page name and the rest are values
for other variables.
You can either decide ahead of time the variable that each value
corresponds to by the order it appears, or you can use other delimiters
other than slash "/" to differentiate between variable name and variable
value. For example: <a style='text-decoration: underline;' href="http://www.rootmode.com/page/value1/value2/value3" target="_blank">www.rootmode.com/page/value1/value2/value3</a> or
<a style='text-decoration: underline;' href="http://www.rootmode.com/page/variable1-value1/variable2-value2/variable3-value3" target="_blank">www.rootmode.com/page/variable1-value1/variable2-value2/variable3-value3</a>
You will have to develop the logic in your index.php for how to treat
the info that is parsed from the URI.
Hope this gives you a path to follow out of the various that are
possible.
--
Edward Alfert - <a style='text-decoration: underline;' href="http://www.rootmode.com/" target="_blank">http://www.rootmode.com/</a>
Coupon Code (Recurring $5/month Discount): newsgroup
Multiple Domain Hosting * Private Label Nameservers<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 4) Posted: Wed Mar 10, 2004 9:46 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <Xns94A87CC7F7B82ealfertrootmodecom DeleteThis @130.133.1.4>,
ealfert DeleteThis @rootmode.com says...
> I use the following for the redesign of my site that is underway.
> The following are snips of the core logic.
Thanks Edward. I can see where your code is leading, and it is certainly
another avenue to try. I have simlar code at my own personal (rather
than rossmore.org) site, alebit in a rather more crude form where
garyjones.co.uk/me/ would forward onto:
garyjones.co.uk/?page=me/index.php, and the PHP uses a simlar method to
yours to put the contents of me/index.php into the root index.php.
Thanks for your suggestion.
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jun 27, 2003 Posts: 571
|
(Msg. 5) Posted: Wed Mar 10, 2004 9:46 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Wed, 10 Mar 2004 18:46:07 -0000, Gazza <gary DeleteThis @garyjones.co.uk.invalid>
wrote:
> In article <Xns94A87CC7F7B82ealfertrootmodecom DeleteThis @130.133.1.4>,
> ealfert DeleteThis @rootmode.com says...
>> I use the following for the redesign of my site that is underway.
>> The following are snips of the core logic.
>
> Thanks Edward. I can see where your code is leading, and it is certainly
> another avenue to try. I have simlar code at my own personal (rather
> than rossmore.org) site, alebit in a rather more crude form where
> garyjones.co.uk/me/ would forward onto:
> garyjones.co.uk/?page=me/index.php, and the PHP uses a simlar method to
> yours to put the contents of me/index.php into the root index.php.
> Thanks for your suggestion.
On <a style='text-decoration: underline;' href="http://www.rossmore.org/," target="_blank">http://www.rossmore.org/,</a> you have no opening <body> tag in an XHTML
1.1 document. This is causing Opera to cry foul and dump code at the user.
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollory that nothing is ridiculous.
- <a style='text-decoration: underline;' href="http://www.greywyvern.com" target="_blank">http://www.greywyvern.com</a> - Orca RingMaker: PHP web ring creation and
management<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 6) Posted: Wed Mar 10, 2004 9:56 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <8%H3c.362$hY6.6244@news7.onvoy.net>, spam RemoveThis @koivi.com says...
> The RewriteRule is a regex. So if you had database ids like
> 'tabletennis', 'art','football8', etc. you could use something like:
>
> RewriteRule ^clubs/([^/]+)/?$ clubs/index.php?id=$1 [L,QSA]
>
> Which would make links like:
> domain.tld/clubs/tabletennis/
> domain.tld/clubs/art/
> domain.tld/clubs/football8/
>
> call these:
> domain.tld/clubs/index.php?id=tabletennis
> domain.tld/clubs/index.php?id=art
> domain.tld/clubs/index.php?id=football8
This looks *extremely* useful, even the exact thing I could be after!
I'll test it out, and get back to the group as to whether it was.
Blimey, never had such a spot-on response so quick.
Thanks Justin.
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 7) Posted: Thu Mar 11, 2004 12:15 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <opr4nurw0pv0in9v.RemoveThis@news.nas.net>,
SP_bhuisman.RemoveThis@greywyvern.com_AM says...
> On Wed, 10 Mar 2004 18:46:07 -0000, Gazza <gary.RemoveThis@garyjones.co.uk.invalid>
> On <a style='text-decoration: underline;' href="http://www.rossmore.org/," target="_blank">http://www.rossmore.org/,</a> you have no opening <body> tag in an XHTML
> 1.1 document. This is causing Opera to cry foul and dump code at the user.
Ta for that - I'm having to test and update on a live site, and I'd
updated some code (making the menu database driven) somehow managing to
delete:
echo '</head><body>';
of which XML was complaining loudly at the time - you obviously looked
just at that time
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 411
|
(Msg. 8) Posted: Thu Mar 11, 2004 12:16 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gazza wrote:
> In article <8%H3c.362$hY6.6244@news7.onvoy.net>, spam.RemoveThis@koivi.com says...
>
>>The RewriteRule is a regex. So if you had database ids like
>>'tabletennis', 'art','football8', etc. you could use something like:
>>
>>RewriteRule ^clubs/([^/]+)/?$ clubs/index.php?id=$1 [L,QSA]
>>
>>Which would make links like:
>>domain.tld/clubs/tabletennis/
>>domain.tld/clubs/art/
>>domain.tld/clubs/football8/
>>
>>call these:
>>domain.tld/clubs/index.php?id=tabletennis
>>domain.tld/clubs/index.php?id=art
>>domain.tld/clubs/index.php?id=football8
>
> This looks *extremely* useful, even the exact thing I could be after!
> I'll test it out, and get back to the group as to whether it was.
> Blimey, never had such a spot-on response so quick.
> Thanks Justin.
[I would have snipped the other groups if I knew which you were reading
from - alt.www.webmaster is where I'm at.]
You're welcome! Glad that it helped you out... Now depending on how far
you want to go, check out <a style='text-decoration: underline;' href="http://demo.wafishermn.com" target="_blank">http://demo.wafishermn.com</a> Sure, the design is
really simple (or non-existant), but it's only there for our clients to
get a taste of what can be accomplished.
Here's the htaccess for that one:
RewriteEngine On
RewriteRule ^/?$ template.php?sec=index [L,NS,QSA]
RewriteRule ^phpsecurityadmin/?(.*) _site_components/phpsecurityadmin/$1
[L,NS,QSA]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteRule .* - [PT]
RewriteRule ^([^/]+)(/([^/]+))?(/([^/]+))?(/([^/]+))?/?$
template.php?sec=$1&page=$3&sub=$5&num=$7 [L,NS,QSA]
--
Justin Koivisto - spam.RemoveThis@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
SEO Competition League: <a style='text-decoration: underline;' href="http://seo.koivi.com/" target="_blank">http://seo.koivi.com/</a><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 9) Posted: Thu Mar 11, 2004 1:03 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <pAL3c.370$hY6.6577@news7.onvoy.net>, spam.DeleteThis@koivi.com says...
> Gazza wrote:
> > In article <8%H3c.362$hY6.6244@news7.onvoy.net>, spam.DeleteThis@koivi.com says...
> >
> >>The RewriteRule is a regex. So if you had database ids like
> >>'tabletennis', 'art','football8', etc. you could use something like:
> >>
> >>RewriteRule ^clubs/([^/]+)/?$ clubs/index.php?id=$1 [L,QSA]
> You're welcome! Glad that it helped you out...
Right, well it's not quite there yet
<a style='text-decoration: underline;' href="http://www.rossmore.org/club/index.php?club=climbing" target="_blank">http://www.rossmore.org/club/index.php?club=climbing</a> works (it's in a
folder called club, not clubs, as the original questions was about, and
yes I've changed the RewriteRule!)
But <a style='text-decoration: underline;' href="http://www.rossmore.org/club/climbing" target="_blank">http://www.rossmore.org/club/climbing</a> or
<a style='text-decoration: underline;' href="http://www.rossmore.org/club/climbing/" target="_blank">http://www.rossmore.org/club/climbing/</a> doesn't.
Am I missing something?
My RewriteRule is:
RewriteRule ^club/([^/]+)/?$ club/index.php?id=$1 [L,QSA]
....and I know rewriting is allowed as RewriteRule ^stats$ webstat
[L,QSA] works.
I checked against your exampple for wafisherman.com, but other than a NS
flag (which seems to have no effect on my code) I can't see anything
that would help.
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 10) Posted: Thu Mar 11, 2004 1:22 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <MPG.1ab9a104ab39fc5198969f.TakeThisOut@news.ntlworld.com>,
gary.TakeThisOut@garyjones.co.uk.invalid says...
> In article <pAL3c.370$hY6.6577@news7.onvoy.net>, spam.TakeThisOut@koivi.com says...
> > Gazza wrote:
> Am I missing something?
My marbles it seems.
> My RewriteRule is:
> RewriteRule ^club/([^/]+)/?$ club/index.php?id=$1 [L,QSA]
....when in fact it should have been:
RewriteRule ^club/([^/]+)/?$ club/index.php?club=$1 [L,QSA]
....to fit in with what I'd written in the rest of the page.
Top marks for Justin. Works like a dream now.
Much appreciative of your time. Do you accept pints via email?  )
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 11) Posted: Thu Mar 11, 2004 1:26 am
Post subject: Re: Mod_rewrite for PHP template - conclusion [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <MPG.1ab955374f2e2d00989697 RemoveThis @news.ntlworld.com>,
gary RemoveThis @garyjones.co.uk.invalid says...
> What I'd like, is for me to be able to link pages, *and users to be able
> to type in page addresses*, as they previously were, but the backend of
> the site to know, for instance, that /clubs/tabletennis/ actually means
> /clubs/index.php?id=12.
As conclusion/finale/summary/feedback type thing:
RewriteEngine on
RewriteBase /
RewriteRule ^clubs/([^/]+)/?$ clubs/index.php?id=$1 [L,QSA]
placed in the root .htaccess file is the required solution to this
problem.
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Apr 29, 2004 Posts: 1010
|
(Msg. 12) Posted: Thu Mar 11, 2004 11:14 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Gazza" <gary.TakeThisOut@garyjones.co.uk.invalid> wrote in message
news:MPG.1ab955374f2e2d00989697@news.ntlworld.com...
> An Apache question - I've had a look on the ALA articles regarding
> friendly URLs, and also the Apache manuals, but I'm not quite sure where
> I need to be heading:
>
> The current setup is at <a style='text-decoration: underline;' href="http://www.rossmore.org/clubs/" target="_blank">www.rossmore.org/clubs/</a> - As you can see, each
> club (albeit missing content on the pages) is situated in their own
> folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
>
> Having gotten into using a database with PHP recently, my aim is to
> create a single template (that would be at /club/index.php) and have it
> pull the club info (time, day, who, where etc) out of a database and
> populate it. I can forsee that this would lead to URLs such as
> /clubs/index.php?id=12 where id 12 tells the db to enter all the info
> for table tennis, say.
>
> What I'd like, is for me to be able to link pages, *and users to be able
> to type in page addresses*, as they previously were, but the backend of
> the site to know, for instance, that /clubs/tabletennis/ actually means
> /clubs/index.php?id=12.
>
> From what I've read, it's mod_rewrite that I need. Closest I came up
> with is:
> RewriteEngine On
> RewriteBase /
> RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
> ...but this didn't seem to work. Any ideas?
> Also, is there a way of using regular expressions, or adding a further
> column in the database so that I don't have a whole list of
> RewriteRules, but one containing a RE instead?
>
Is your question really an Apache one? or could it be a php one?
Sugestion:
Why not stay with php and use case e.g.
<?php
switch ($page) {
case tabletennis :
$page_selected = index.php?id=12;
break;
case football :
$page_selected = index.php?id=13;
break;
case art :
$page_selected = index.php?id=14;
break;
default :
index.php?id=1;
}
?>
Needs polish but would do the trick
--
bildanet
MyLot.net - the home of the $10 reseller programme<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 50
|
(Msg. 13) Posted: Thu Mar 11, 2004 11:14 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <404f6b08.TakeThisOut@clear.net.nz>, who.TakeThisOut@what.com says...
>
> "Gazza" <gary.TakeThisOut@garyjones.co.uk.invalid> wrote in message
> news:MPG.1ab955374f2e2d00989697@news.ntlworld.com...
> > An Apache question - I've had a look on the ALA articles regarding
> > friendly URLs, and also the Apache manuals, but I'm not quite sure where
> > I need to be heading:
> >
> > The current setup is at <a style='text-decoration: underline;' href="http://www.rossmore.org/clubs/" target="_blank">www.rossmore.org/clubs/</a> - As you can see, each
> > club (albeit missing content on the pages) is situated in their own
> > folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
> >
> > Having gotten into using a database with PHP recently, my aim is to
> > create a single template (that would be at /club/index.php) and have it
> > pull the club info (time, day, who, where etc) out of a database and
> > populate it. I can forsee that this would lead to URLs such as
> > /clubs/index.php?id=12 where id 12 tells the db to enter all the info
> > for table tennis, say.
> >
> > What I'd like, is for me to be able to link pages, *and users to be able
> > to type in page addresses*, as they previously were, but the backend of
> > the site to know, for instance, that /clubs/tabletennis/ actually means
> > /clubs/index.php?id=12.
> >
> > From what I've read, it's mod_rewrite that I need. Closest I came up
> > with is:
> > RewriteEngine On
> > RewriteBase /
> > RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
> > ...but this didn't seem to work. Any ideas?
> > Also, is there a way of using regular expressions, or adding a further
> > column in the database so that I don't have a whole list of
> > RewriteRules, but one containing a RE instead?
> >
> Is your question really an Apache one? or could it be a php one?
>
> Sugestion:
> Why not stay with php and use case e.g.
>
> <?php
> switch ($page) {
> case tabletennis :
> $page_selected = index.php?id=12;
> break;
>
> case football :
> $page_selected = index.php?id=13;
> break;
>
> case art :
> $page_selected = index.php?id=14;
Certainly a possible solution, except that we could end up with 30 clubs
- I'd see it as more efficient to have one RE controlling this action
than heading towards 100 hundred lines of PHP...?
--
Gazza
<a style='text-decoration: underline;' href="http://www.rossmore.org/" target="_blank">http://www.rossmore.org/</a>
<a style='text-decoration: underline;' href="http://www.garyjones.co.uk/" target="_blank">http://www.garyjones.co.uk/</a>
"Some people don't listen, they simply wait to speak"<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Mar 10, 2004 Posts: 1
|
(Msg. 14) Posted: Thu Mar 11, 2004 11:14 am
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gazza wrote:
> In article <404f6b08.RemoveThis@clear.net.nz>, who.RemoveThis@what.com says...
>>
>> "Gazza" <gary.RemoveThis@garyjones.co.uk.invalid> wrote in message
>> news:MPG.1ab955374f2e2d00989697@news.ntlworld.com...
>> > An Apache question - I've had a look on the ALA articles regarding
>> > friendly URLs, and also the Apache manuals, but I'm not quite sure
>> > where I need to be heading:
>> >
>> > The current setup is at <a style='text-decoration: underline;' href="http://www.rossmore.org/clubs/" target="_blank">www.rossmore.org/clubs/</a> - As you can see, each
>> > club (albeit missing content on the pages) is situated in their own
>> > folder, so /clubs/art/, /clubs/football8/, /clubs/tabletennis/ etc.
>> >
>> > Having gotten into using a database with PHP recently, my aim is to
>> > create a single template (that would be at /club/index.php) and have it
>> > pull the club info (time, day, who, where etc) out of a database and
>> > populate it. I can forsee that this would lead to URLs such as
>> > /clubs/index.php?id=12 where id 12 tells the db to enter all the info
>> > for table tennis, say.
>> >
>> > What I'd like, is for me to be able to link pages, *and users to be
>> > able to type in page addresses*, as they previously were, but the
>> > backend of the site to know, for instance, that /clubs/tabletennis/
>> > actually means /clubs/index.php?id=12.
>> >
>> > From what I've read, it's mod_rewrite that I need. Closest I came up
>> > with is:
>> > RewriteEngine On
>> > RewriteBase /
>> > RewriteRule ^clubs/tabletennis clubs/index\.php?id=12
>> > ...but this didn't seem to work. Any ideas?
>> > Also, is there a way of using regular expressions, or adding a further
>> > column in the database so that I don't have a whole list of
>> > RewriteRules, but one containing a RE instead?
>> >
>> Is your question really an Apache one? or could it be a php one?
>>
>> Sugestion:
>> Why not stay with php and use case e.g.
>>
>> <?php
>> switch ($page) {
>> case tabletennis :
>> $page_selected = index.php?id=12;
>> break;
>>
>> case football :
>> $page_selected = index.php?id=13;
>> break;
>>
>> case art :
>> $page_selected = index.php?id=14;
>
> Certainly a possible solution, except that we could end up with 30 clubs
> - I'd see it as more efficient to have one RE controlling this action
> than heading towards 100 hundred lines of PHP...?
Why not use the database to manage this part of it too ?
"select id from pages where page='$page'" ?
--
+---+
| n | <a style='text-decoration: underline;' href="http://www.n-gate.net" target="_blank">www.n-gate.net</a>
+---+<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2003 Posts: 21
|
(Msg. 15) Posted: Thu Mar 11, 2004 12:56 pm
Post subject: Re: Mod_rewrite for PHP template [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gazza <gary.TakeThisOut@garyjones.co.uk.invalid> writes:
> What I'd like, is for me to be able to link pages, *and users to be able
> to type in page addresses*, as they previously were, but the backend of
> the site to know, for instance, that /clubs/tabletennis/ actually means
> /clubs/index.php?id=12.
Sure you can do this with mod_rewrite but there doesn't seem to be any
good way of linking tabletennis to id=12 without resorting to a load
of rules.
Why don't you just have a wrapper to index.php which does it for you?
You won't be able to use "clubs" as you've used that already, but you
could use "club" or anything else you like.
Make the new script read the $_SERVER["PATH_INFO"] variable and
split() on "/" to get the long name. Then lookup the id in any manner
you choose (array, DB, whatever) set the variable that index.php needs
and include index.php.
You may need to change index.php to check for a new variable depending
on how you've done it.
The final step would be to instruct apache to treat your new
script (called "club" or whatever) as a php script even without the
..php on the end. Look at the <File> directive for that. You may also
have to set AcceptPathInfo On if you're using apache2.
HTH.
--
Richard Watson
<a style='text-decoration: underline;' href="http://www.opencolo.com/" target="_blank">http://www.opencolo.com/</a>
High Quality, Value for money colocation<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Mod_rewrite for PHP template |
|
| Back to top |
|
 |  |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|