Re: Apache"s mod_rewrite Help
am 02.10.2007 20:50:09 von php.developer2007
> > Anybody can explain Apache's mod_rewrite technique so that i can use
> > this technique.
>
> The documentation of apache is fairly complete.www.apache.org
>
> Davide
Hi,Thanks for your reply.Yeah i know that apache documents are
complete but basicly i m new to this type of coding and i want to use
this concept in Php.If you know can you help me out with code.I m very
thankfull for ur help.
My problem is that :
For example link is this
www.example.com/foo123
i want to have "foo123" in my php file for further processing.Thanks
Re: Apache"s mod_rewrite Help
am 11.10.2007 11:53:34 von sean dreilinger
hi, from the information you've offered, it sounds more like a php question than
an apache question. the server variables populated by apache are available to
php programs in an array called $_SERVER[]; this page in the php manual
documents them:
http://us2.php.net/manual/en/reserved.variables.php#reserved .variables.server
when a user requests the URI /foo123 from your web server, your php script that
handles these requests would look for a URI that matches /foo123, and issue some
instructions:
if ( preg_match( "#^/foo123#", $_SERVER["REQUEST_URI"] ) ) {
send123(); # function you've written to handle this case
exit(0);
} elseif ( preg_match( "#^/foo456#", $_SERVER["REQUEST_URI"]) ) {
send456(); # function you've written to handle this case
exit(0);
}
i suspect you'll get way better advice from a php-oriented discussion group.
good luck!
-sean
--
sean dreilinger - http://durak.org/sean/
Php Developer wrote:
> Hi,Thanks for your reply.Yeah i know that apache documents are
> complete but basicly i m new to this type of coding and i want to use
> this concept in Php.If you know can you help me out with code.I m very
> thankfull for ur help.
> My problem is that :
> For example link is this
> www.example.com/foo123
> i want to have "foo123" in my php file for further processing.Thanks
Re: Apache"s mod_rewrite Help
am 12.10.2007 20:05:15 von klenwell
On Oct 11, 2:53 am, sean dreilinger wrote:
> hi, from the information you've offered, it sounds more like a php question than
> an apache question. the server variables populated by apache are available to
> php programs in an array called $_SERVER[]; this page in the php manual
> documents them:
>
> http://us2.php.net/manual/en/reserved.variables.php#reserved .variable...
>
> when a user requests the URI /foo123 from your web server, your php script that
> handles these requests would look for a URI that matches /foo123, and issue some
> instructions:
>
> if ( preg_match( "#^/foo123#", $_SERVER["REQUEST_URI"] ) ) {
> send123(); # function you've written to handle this case
> exit(0);} elseif ( preg_match( "#^/foo456#", $_SERVER["REQUEST_URI"]) ) {
>
> send456(); # function you've written to handle this case
> exit(0);
>
> }
>
> i suspect you'll get way better advice from a php-oriented discussion group.
>
> good luck!
> -sean
>
> --
> sean dreilinger -http://durak.org/sean/
>
> Php Developer wrote:
> > Hi,Thanks for your reply.Yeah i know that apache documents are
> > complete but basicly i m new to this type of coding and i want to use
> > this concept in Php.If you know can you help me out with code.I m very
> > thankfull for ur help.
> > My problem is that :
> > For example link is this
> >www.example.com/foo123
> > i want to have "foo123" in my php file for further processing.Thanks
This is the basic concept. But usually the request uri is rewritten
so as to direct to a controller or dispatch script with a query
string.
So, for example, I'll often use a uri like this:
www.example.com/view/foo123/
And then set my rewrite rule in .htaccess to something like this:
^view/(.*) -> index.php?view=$1
Then in index.php, you have a case tree like Sean presented above:
if ( $_GET['view'] == 'foo123' )
{
send_to_script($_GET['view']);
}
That's a rough outline of what you're probably trying to do. Google
some combination of php, mod_rewrite, apache, and "clean urls", and
you can find more detailed guides.