Solved

complex rewrite rule for mod rewrite

Posted on 2008-10-24
3
202 Views
Last Modified: 2013-12-13
Hello Experts,
i´m really confused on writing a mod rewrite rule for my webpage runing on Apache Webserver. I have never done this befor and don´t know how to start. I only know how to make the .htaccess file and set the rule but don´t know how to write the rule.

i have a php script which need several params the link to a site look like:

index.php?id=1&city=Berlin&country=DE&zip=01234&uk=50&ed=today
or
index.php?id=1&city=Berlin&country=DE&zip=01234&uk=50&ed=tommorrow
or
index.php?id=1&city=Berlin&country=DE&zip=01234&uk=50&ed=20081023&page=3

The arrangement of the params can be different and params can be missing.

for example:
index.php?id=1&country=DE&zip=01234&city=Berlin&uk=50&ed=20081023
or
index.php?id=1&zip=01234&city=Berlin

how to write a rewrite rule that will give the following result?

mypage/Country-Zip-Cityname/20081023/index.html
or
mypage/Country-Zip-Cityname/today/index.html
or
mypage/Country-Zip-Cityname/today/page_1.html

what happens if the country or zip param is not set?
0
Comment
Question by:bibabutze
  • 2
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> how to write a rewrite rule that will give the following result?
> mypage/Country-Zip-Cityname/20081023/index.html

assuming that you mean the value from the parameter for the literals "Country", "Zip" and so on, what should be the value if the parameter is missing as in
> index.php?id=1&zip=01234&city=Berlin

What happens to the id= parameter
0
 

Author Comment

by:bibabutze
Comment Utility
the id=1 is the default param. if you enter the site the id param is not set. If the id param is set it should look like mypage/Country-Zip-Cityname/20081023/1_index.html.

Also when i enter  mypage/Cityname
the url should look like index.php?city=Berlin

is this possible with mod_rewrite

0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
Comment Utility
hmm, it's getting more confuse as you last post expects a rewriting which is exactly the oposite of what you describe in the question, I'll give a suggestion for your question!

RewriteCond   %{REQUEST_URI}  !^/*mypage/$
RewriteCond   %{REQUEST_URI}  *index.php
RewriteRule index.php\?id=([^&])&city=([^&])&country=([^&])&zip=([^&])&uk=([^&])&ed=([^&])&page=([^&])   /mypage/$3-$4-$2/&$6/page_$7.html [L]

> The arrangement of the params can be different and params can be missing.
then you have to use a RewriteRule like above for each variant of these arrangements
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now