Solved

htaccess: reorder variables in clean-urls using RewriteRule

Posted on 2009-05-08
9
830 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

20 Experts available now in Live!

Get 1:1 Help Now