For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > January 2005 > URL rewriting









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author URL rewriting
Ricky Romaya

2005-01-26, 3:56 am

Can I have somekind of URL rewriting mechanism without touching the web
server's configuration (implemented in pure PHP) and win32 compatible? All
the info I have teaches about apache's mod_rewrite or other methods which
includes httpd.conf/htaccess editing. Assume I don't have any access to
both files.
R. Rajesh Jeba Anbiah

2005-01-26, 3:56 pm

Ricky Romaya wrote:
> Can I have somekind of URL rewriting mechanism without touching the

web
> server's configuration (implemented in pure PHP) and win32

compatible? All
> the info I have teaches about apache's mod_rewrite or other methods

which
> includes httpd.conf/htaccess editing. Assume I don't have any access

to
> both files.


Explain what you want to achieve, like "from" and "to" URLs?

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Ricky Romaya

2005-01-26, 3:56 pm

"R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in
news:1106756528.100684.128870@f14g2000cwb.googlegroups.com:
>
> Explain what you want to achieve, like "from" and "to" URLs?
>

Well, at least the same basic functionality of Apache's mod_rewrite. For
example, this URL:

http://www.foobar.com/en/my-index/

will be translated to

http://www.foobar.com/index.php?lang=en&page=my-index

before the webserver finally calls index.php with 'lang' and 'page'
arguments.
R. Rajesh Jeba Anbiah

2005-01-27, 8:56 pm

Ricky Romaya wrote:
> "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in
> news:1106756528.100684.128870@f14g2000cwb.googlegroups.com:
> Well, at least the same basic functionality of Apache's mod_rewrite.

For
> example, this URL:
>
> http://www.foobar.com/en/my-index/
>
> will be translated to
>
> http://www.foobar.com/index.php?lang=en&page=my-index
>
> before the webserver finally calls index.php with 'lang' and 'page'
> arguments.


I don't think, this case will be possible then. But, will be happy
if someone proves the other.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

NC

2005-01-27, 8:56 pm

Ricky Romaya wrote:
>
> Can I have somekind of URL rewriting mechanism without
> touching the web server's configuration (implemented
> in pure PHP) and win32 compatible?


Not really... URL rewriting is a pretty low-level HTTP
server functionality... This said, there may be ways
to make your URLs shorter and prettier...

> For example, this URL:
>
> http://www.foobar.com/en/my-index/
>
> will be translated to
>
> http://www.foobar.com/index.php?lang=en&page=my-index
>
> before the webserver finally calls index.php with
> 'lang' and 'page' arguments.


Again, URL rewriting is out of question, so what I am about
to suggest is more like alternative ways of communicating
values without communicating names.

There is a hack (which I really don't recommend because I am
not sure this apache behavior is intended)... Call your home
page like this:

http://www.foobar.com/index.php/en/my-index/

This should set your $_SERVER['PHP_SELF'] to "/en/my-index/",
which you can then parse like this:

$vars = explode('/', $_SERVER['PHP_SELF']);
$lang = $vars[1];
$page = $vars[2];

There is another hack, more standards-friendly:

http://www.foobar.com/?en/my-index/

This should set your $_SERVER['QUERY_STRING'] to "en/my-index/"
which you can parse like this:

$vars = explode('/', $_SERVER['QUERY_STRING']);
$lang = $vars[0];
$page = $vars[1];

Cheers,
NC

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com