Solved

htaccess: reorder variables in clean-urls using RewriteRule

Posted on 2009-05-08
9
849 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your 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
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

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.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 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