473,441 Members | 1,838 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,441 software developers and data experts.

Apache mod rewrite for multiple variables?

I need a rewrite rule/rules for an .htaccess file that does the following...
if a second variable is supplied...
rewrites this... artistcat_VAR1_VAR2.htm --> artists.php?cat=VAR1&page=VAR2
if only the first variable is supplied...
rewrites this... artistcat_VAR1.htm --> artists.php?cat=VAR1

Thanks guys!
Nov 29 '06 #1
2 5249
I would just just rewrite one main back-reference (variable)
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Then explode it on the backend to whatever amount of variables you please, depending on a chosen delimiter (in this case, / is the delimiter)
Expand|Select|Wrap|Line Numbers
  1. $query = strtolower($_GET['q']);
  2. list($whateverID, $articletype) = explode('/', $query);
That way, if example.com/foo is rewritten, $whateverID would be 'foo' and $articletype would be nothing. If example.com/foo/steve is rewritten, $whateverID would be 'foo' and $articletype would be 'steve'

Hope this helps.

Ben
Feb 17 '07 #2
Motoma
3,237 Expert 2GB
This is a good tutorial on mod_rewrite. I believe it covers just the sort of thing you are trying to do, using regular expressions.
Feb 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Phil Powell | last post by:
http://www.sitepoint.com/article/910/2] How can it be possible to use Apache's mod_rewrite module in such a way as to dynamically feed it variable information into the "RewriteRule" option? I...
5
by: Vitali Malicky | last post by:
Hello dear All! I need to print out and pass apache evironment variables (like HTTP_HOST, SERVER _NAME, REMOTE_ADDR) to another program which is to process them and take definite actions...
1
by: Kim Gijung | last post by:
Hi all, I'm wondering how the apache server and php interepreter handles request. If one request comes to apache server what is next procedure? if apache server passes the request to php...
56
by: Anonymous, quoting Philip Ronan | last post by:
Subject: Warning: robots.txt unreliable in Apache servers From: Philip Ronan <invalid@invalid.invalid> Newsgroups: alt.internet.search-engines Message-ID: <BF89BF33.39FDF%invalid@invalid.invalid>...
3
by: genenamg | last post by:
Hi, I am trying to run and configure Apache 2.0, php 5 and mysql on win xp professional - this is the first time I have tried to install and configure all three. I am having difficulty trying...
5
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major...
5
by: Danilo | last post by:
Hi there, is it possible to create a rewrite rule to send every server-request to the directory /py? But only if the file does not exists on the server. This is my mod_python section of the...
8
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
6
by: josequinonesii | last post by:
I've searched, I've read, I've tested and re-read numerous post but to no avail yet... Quite simply, the settings I've applied to my httpd.conf, httpd-vhost.conf and my hosts files simply does not...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.