Solved

complex rewrite rule for mod rewrite

Posted on 2008-10-24
3
206 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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

860 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