Solved

complex rewrite rule for mod rewrite

Posted on 2008-10-24
3
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22804644
> 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
ID: 22810449
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
ID: 22824337
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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