Solved

complex rewrite rule for mod rewrite

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 dynamically set the form action using jQuery.

867 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

15 Experts available now in Live!

Get 1:1 Help Now