2

I would like to know how can I rewrite www.site.com?lang=lv&type=1&mode=2 into www.site.com/lv/1/2 using Apache mod_rewrite options.

3 Answers 3

2

Assuming that you actually want to rewrite /lv/1/2 to ?lang=lv&type=1&mode=2 (I see no reason to do the opposite) and that no other rewrites are active, this should do the trick:

RewriteRule ^/([^/]*)/([^/]*)/([^/]*)$ ?lang=$1&type=$2&mode=$3 [L]

Also; you'd be better off replacing those magic numbers with more useful information if you want to include them in your URI.

Edit: If it really is the opposite you'd like to do, see the answer by Matt S.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I ment the opposite :P Thank you!
0

Basic rewrite:

RewriteEngine On
RewriteRule http://www.site.com/?lang=(.+?)&type=(\d+?)&mode=(\d+?) http://www.site.com/$1/$2/$3 [L,R=permanent]

Edit: Changed rewrite flags to force a permanent redirect

2 Comments

That does seem to be working:The requested URL was not found on this server.
Do you have a page that responds to site.com/lv/1/2? Are you using a framework of some kind?
0

You need to handle the URI path and query separately. If the parameters appear in that very same order, you can do this:

RewriteCond %{QUERY_STRING} ^lang=([^&]+)&type=([^&]+)&mode=([^&]+)$
RewriteRule ^$ /%1/%2/%3? [L,R=301]

Otherwise you will need to put them in the right order before using this rule or take each parameter at a time.

5 Comments

None of these is working any way, is there something else I need to change in Apache configuration or other?
@werd: Are you using the obligatory RewriteEngine on? And where do you want to use that rule?
Yes I am using it, I am using it on site index. In root directory I have index.php and .htaccess files
@werd: Are you using any other rules that can conflict with this one?
@werd: And the URL path is always just / and there are always these three URL parameters all having a value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.