Need a new rule

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 21 Jun 2016, 16:40

Need a new rule

22 Jun 2016, 14:13

Hi
I need to create a rewrite rule for a multi language app where the language is stored in the URL. For example:

http://[domain]/[langcode]/default.asp
should redirect to:
http://[domain]/default.asp?lang=[langcode]

This should work for any subdirectories so for example:
http://[domain]/[langcode]/path/to/directory/somefile.asp?par=val
should redirect to:
http://[domain]/path/to/directory/somefile.asp?par=val&lang=[langcode]

I need a single rule to work for multiple levels of subdirectory and in addition, I need the rule (or a 2nd rule) to also handle any number of parameters.

Basically, whatever the URL I need to extract the language code from the URL and append it as an additional parameter on the URL.

I saw the following rule:

RewriteRule /(\w+)/([^?]*)(\?.*)? http\://www.domain.com/$2?3$3&lang=$1:\?lang=$1 [I,RP]

However I am having 2 issues with this rule.

1. It doesnt seem to work on ssl pages (https)

2. If a user doesnt not type in a language it should just default as no language supplied.

So for example I have the following:

RewriteRule ^[^?/]*-(\d+)$ item.asp?pid=$1 [NC,L,QSA]

which would produce smth like this

http://www.xyz.com/item.asp?pid=233 ---> http://www.xyz.com/bla-bla-bla-233

Now I need to add languages so if a user enters

http://[domain]/bla-bla-bla-233 (this shows in english - or no langunge in the querystring would essesntially just look like http://[domain]/item.asp?pid=233&lan=)

However if a user enters http://[domain]/br/bla-bla-bla-233 it would direct someone to http://[domain]/item.asp?pid=233&lan=br

Ideally I have multiple URL rewrites already so i would add one last rule to my file to check for

http://[domain]/(language)/

if it is found always append it to the querystring as such "lan=whateverlangauge"


Can anybody suggest how this can be made possible?

Thanks

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 14 guests