Solved

complex rewrite rule for mod rewrite

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

739 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