?
Solved

htaccess: reorder variables in clean-urls using RewriteRule

Posted on 2009-05-08
9
Medium Priority
?
888 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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
yes, ravenpl is right:
entering the following in the browser
http://mydomain.com/de/welcome/1000/317/1921680156521/f10.0.22

should call
http://mydomain.com/site2009/pages/welcome.php?sid=de|1000|317|f10.0.22|1921680156521|welcome
behind the scenes
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 1000 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 1000 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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

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

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 …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

839 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