Last post Jul 21, 2016 07:37 AM by sudip_inn
Jun 30, 2016 12:54 PM|sudip_inn|LINK
now i want to introduce country code into all url. before my url look like
but now i want to write some code in global place which will inject 2 char country code in all url. so my new url would look like
so tell me what code i need to add in global area of web site which inject country code in url. discuss with code example. thanks
Jun 30, 2016 02:15 PM|bbcompent1|LINK
Sudip, what you are after is called URL Rewriting. I trust you have these international sites in directories of their own. So what you can do is first, install IIS URL Rewrite Module. Here follows some instructions from a TechNet blog that helped me get
URL Re-writing going:
Download and install the
IIS URL Rewrite module from IIS.net.
1. If IIS Manager is running when you install URL Rewrite, you will need to close and reopen it in order to see the URL Rewrite configuration tool icon.
2. Next, I will copy the files and folder necessary to set up my web site.
Don’t close the command prompt yet. We still need it for subsequent steps.
3. I will create a web site which maps to the folder above and has two bindings, using host headers.
From the command line, run 02-create_site.bat to create the web site.
4. On the Internet, we’d need to add both hostnames to DNS so that users can surf to the site.
In our test environment, we simply add this to the HOSTS file on any computer we’re testing from.
5. We will now create the URL Rewrite rule which maps the short url to the long url.
6. In the URL Rewrite configuration, click on the Add Rule(s) link in the Actions pane on the right hand side.
7. Select the Blank rule template and click OK.
8. In the Edit Inbound Rule screen,
9. Click the down arrow to expand the Conditions title, then click Add.
10. In the Add Condition dialog,
Scroll down further to the Action section.
Click the Apply link on the top right of the Actions pane.
The configuration is saved to the web.config file in your web site folder. You may open this web.config file to review how the configuration is being created under the hood.
Let’s review what we just did from step 8 to 11:
If you browse to http://shorturl.com/abc.htm, the url will rewrite to
However, if you browse to http://verylongurl.com/abc.htm, the url will
not be rewritten because it does not match the host name we are looking for, which is “shorturl.com”.
To see this in action, browse to the following pair of urls and you should see that each pair will show you the same page.
You can learn more about URL Rewrite module here.
Download the sample file here:
Now, once you have this URL Re-writing configured, you are going to need to use some type of GeoLocation API (not foolproof if user IP is spoofed) but you can use HTML5 GeoLocation API:
http://html5demos.com/geo or http://dev.w3.org/geo/api/spec-source.html
Now, when the user comes to your site you can get a response back from the HTML5 Geo API to determine what their country should be. Then take that and wire up your URL Rewriting to send them to a specific language URL based on the geolocation country spec.
Take a look and get back to me if you need more help with coding it up.
Jul 19, 2016 06:39 PM|sudip_inn|LINK
Jul 20, 2016 06:51 PM|bbcompent1|LINK
Any libraries required should be installed along with it. Let me know if you have any troubles.
The URL Rewrite Module does not need any additional DLL files. As I understand it, it is a drop and go module.
Jul 21, 2016 07:37 AM|sudip_inn|LINK
sorry to say this answer is not good answer. you should mention the name here.