473,385 Members | 1,325 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,385 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 5248
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.