Solved

htaccess: reorder variables in clean-urls using RewriteRule

Posted on 2009-05-08
9
863 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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
 

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

Independent Software Vendors: 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

Suggested Solutions

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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