Solved

htaccess: reorder variables in clean-urls using RewriteRule

Posted on 2009-05-08
9
840 Views
Last Modified: 2012-05-06
Hi,
Currently our URLs look like that:

http://mydomain.com/site2009/pages/welcome.php?sid=de|1000|317|f10.0.22|1921680156521|welcome

We want to use clean-urls - the solution should be made using htaccess so that the URLs look like that:
http://mydomain.com/de/welcome/1000/317/1921680156521/f10.0.22

Many thanks in advance!
0
Comment
Question by:fellz
  • 4
  • 4
9 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 24342512
You need to use http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap with external rewriting program.
0
 

Author Comment

by:fellz
ID: 24342722
Thanks for the hint. However - what I'm looking for is the complete solution (htaccess-code) to paste it and go.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 24342727
RewriteCond %{REQUEST_URI} /site2009/pages/welcome.php
RewriteRule ^.*welcome.php\?sid=([^|]*)\|([^|]*)\|([^|]*)\|([^|]*)\|([^|]*)\|(.*) /$1/welcome/$2/$3/$5/$4
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24342768
ahoffmann, the rule should go the other way i suppose. And I assume the number of variables(the length of url) is variable - that's why suggested external rewrite map.
0
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.

 

Author Comment

by:fellz
ID: 24345161
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 250 total points
ID: 24345212
If the number of variables is constant then (You could also create similar rules for other variables count)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /site2009/pages/$6.php?sid=$1|$3|$4|$6|$5|$2 [L]
0
 

Author Comment

by:fellz
ID: 24349994
many thanks for the solution, ravenpl!
there's just one more question: is there a chance to make it work when the number of variables is not constant but at least limited to a maximum of say 10 variables?
0
 
LVL 43

Assisted Solution

by:ravenpl
ravenpl earned 250 total points
ID: 24350002
Yes.
Either create one rule for every possible number of variables
Or use the external rewrite map.
0
 

Author Closing Comment

by:fellz
ID: 31579531
great! many thanks!
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

861 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

22 Experts available now in Live!

Get 1:1 Help Now