473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Mod_Rewrite / Regex to PHP URL

I am new to using mod_rewrite and am trying to rewrite a URL to pass values to
my script so that:

http://www.myclient.com/everything/animals/mammals/cats

is transformed into

http://www.myclient.com/index.php?nav[0]=everything&nav[1]=animals&nav[2]=mammals@nav[3]=cats

Specifically, I am looking for an n-ary solution to this problem. I know how to
do it for a discrete number, but how do I do this transformation when the number
of variables to go into the nav array is unknown, and how do I generate the
index number? Can any experience mod_rewrite gurus point me in the right
direction. I'm sure this is a common design pattern.

Thanks.
Feb 14 '07 #1
3 2304
Rik
On Thu, 15 Feb 2007 00:15:34 +0100, Dr. No <no@no.nowrote:
I am new to using mod_rewrite and am trying to rewrite a URL to pass
values to my script so that:

http://www.myclient.com/everything/animals/mammals/cats

is transformed into

http://www.myclient.com/index.php?nav[0]=everything&nav[1]=animals&nav[2]=mammals@nav[3]=cats

Specifically, I am looking for an n-ary solution to this problem. I know
how to do it for a discrete number, but how do I do this transformation
when the number of variables to go into the nav array is unknown, and
how do I generate the index number? Can any experience mod_rewrite gurus
point me in the right direction. I'm sure this is a common design
pattern.
As far as I know you cannot, not without really messy toying with
environmental variables.

As you're using PHP, what's wrong with:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?nav=$1

And in PHP:

$nav = isset($_GET['nav']) ? explode('/',$_GET['nav']) : array();
--
Rik Wasmus
Feb 15 '07 #2
"Dr. No" <no@no.nowrote in message
news:qK******************@newssvr11.news.prodigy.n et...
>I am new to using mod_rewrite and am trying to rewrite a URL to pass values
to my script so that:

http://www.myclient.com/everything/animals/mammals/cats

is transformed into

http://www.myclient.com/index.php?nav[0]=everything&nav[1]=animals&nav[2]=mammals@nav[3]=cats

Specifically, I am looking for an n-ary solution to this problem. I know
how to do it for a discrete number, but how do I do this transformation
when the number of variables to go into the nav array is unknown, and how
do I generate the index number? Can any experience mod_rewrite gurus point
me in the right direction. I'm sure this is a common design pattern.

Just use empty brackets: nav[]=everything&nav[]=animals&nav[]=mammals, php
will understand this and create the index numbers for you.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 15 '07 #3
Rik wrote:
As you're using PHP, what's wrong with:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?nav=$1

And in PHP:

$nav = isset($_GET['nav']) ? explode('/',$_GET['nav']) : array();
Or even:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

And in PHP:
$_GET['nav'] = explode('/',$_SERVER['PATH_INFO']);

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Westcoast Sheri | last post by:
Hello. How do I do this: If a visitor types in any number after my url, I want mod_rewrite to convert it to my url/anotherpage.html?number=number_visitor_typed Example: ...
4
by: Support | last post by:
Hello, I am running RedHat & Apache. RedHat does not allow creating more that 32000 subdirectories in one folder due to #defined constant limitation in the core code. I need to display 47000...
1
by: Shabam | last post by:
In Apache there's a pretty powerful module called mod_rewrite. Is there anything like that in dot net?
6
by: namemattersnot | last post by:
ok. i give up. need help :) here's the rule: RewriteRule ^test/(.+)/(.*)$ /index.php$2 if i request: http://localhost/test/keyword/?show=files it properly redirects me. NOW, if i change...
11
by: joelbyrd | last post by:
I have a people-networking type site in which each user has their own profile page, with their user id encoded. So, for example, the web address of their page might look like...
4
by: Hermann.Richter | last post by:
I want to rewrite URLs like http://domain/dir/file.php?var1=val1&var2=val2#anchor to http://domain/dir/file?var1=val1&var2=val2#anchor In other words, I want to strip out the php extension ...
5
by: laredotornado | last post by:
Hi, I have verified that mod_rewrite is enabled on my Apache 2.2 instance. However, now I'm having a problem just serving pages using .htaccess files. Following Rik's advice, my .htaccess file...
1
by: cheesecaker | last post by:
Hi, I need a specific redirect out of mod_rewrite, and I've never done regex a day in my life. Understandably, this makes things difficult. Been trying for hours, now I give up trying to slave it out...
7
by: Dale | last post by:
again, i know this is OT...just move along to the next post if it bugs you. :) i had been trying to have this: project.66.204.32.110 from the client browser, map to a virtual host where the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.