I have a web of which I have two versions: one in spanish and one in english. They are located in different servers and different domains. So they actually behave as two different websites.
I only have one ASP .NET project, and depending on the domain, I show all texts in spanish or in english. That's working right.
I developed it first in spanish, so my page names are written in spanish, like "Buscar.aspx" ("Buscar" means "Search").
I would like to translate also the page's name, so that in browser's address bar, it would appear the english names. For instance, for my page "Buscar.aspx" I would like to appear "Search.aspx" in the address bar.
So my question is: is there any way to declare some kind of "alias" (or some other mechanism), so that I can process requests to "Buscar.aspx" and "Search.aspx" through one single ASP .NET page, but still appearing in the address bar as two different addresses?
URL Rewriting
You could rewrite Search.aspx to Buscar.aspx
<rewrite>
<rules>
<rule name="Search">
<match url="^Search.aspx" />
<action type="Rewrite" url="Buscar.aspx" />
</rule>
</rules>
</rewrite>
These rules could then be put in your English web.config file
Have a look at routing. You can find some documentation here: ASP.NET Routing
Routing means that you can specify a path that maps to a certain ASPX. If you switch the routing configuration based on your language setting you have what you need :)
Related
Have a .net webapp running on IIS.
I have run across something I haven't had to really deal with before. we have partners or clients that have their own "pages" on our domain. currently the URL is www.mydomain.com/?code=partnercode, but for ease of use on business cards and such they want it to be more like www.mydomain.com/partnername and I am not sure how to do this.
I know we can do something like the following in the htaccess in Apache
RewriteRule ^partnername$ index.php?code=partnerid [L]
I am wondering if there is some way to do this in the web.config? there has got to be something, but I am unsure where to look to find it. I have tried those online htaccess to web.config code converters and it failed miserably. The other thing is I would prefer to not have to change the partnerID that we already have in the DB.
I found this on another question on this site but I don't think it will do what I need it to. It will change the URL in the browser one the user hits the page but I also want it to be accessible using the www.mydomain.com/partnername URL as well.
if ( $_SERVER['REQUEST_URI'] == '/index.php?code=partnerid') {
echo '<script type="text/javascript">window.history.pushState("", "", "/partnername");</script>';
}
IIS has extension that partially supports your scenario, it is called URL Rewrite.
I said partially, because you can use it to rewrite URLs from www.mydomain.com/partnername to www.mydomain.com/?code=partnername. What it doesn't support (at least I don't think it does) is mapping a partner name to partner code (unless you have small number of partners and you can add rewrite rule for every partner).
And here is an article showing a fraction of what you can do with URL Rewrite.
In your case if you want to rewrite www.mydomain.com/partnername to www.mydomain.com/?code=partnername, your rule configuration could look something like this (not tested on IIS):
<rewrite>
<rules>
<rule name="Rewrite to query string">
<!-- I'm using hardcoded text, but it is regular expression and you can
write very advanced conditions -->
<match url="^(partner)" />
<!-- changes incoming url /partner to ?code=partner -->
<action type="Rewrite" url="?code={R:1}" />
</rule>
</rules>
</rewrite>
I'm new to the IIS URL Rewrite tool and need some help with my configuration (http://www.iis.net/downloads/microsoft/url-rewrite):
I need to redirect all the old product links from an old shop system (using .html links) to our new shop system (using a longer path and .aspx links).
The old URLs are built like this: www.domain.com/[product number].html
I need them like this: www.domain.com/path1/path2/[same product number].aspx
path1 and path2 are fixed, they don't change at all.
I tried lots of different tips (from google and also from stackoverflow), this is what came out (but did not work - I get the new URL, but the product number is empty):
<rule name="HTML zu ASPX" stopProcessing="true">
<match url="([_0-9a-z-]+)\.html" />
<action type="Redirect" url="path1/path2/{R:1}.aspx" />
Any ideas? Any questions I forgot/didn't know to be asked?
Thanks in advance
Daniel
Make sure browser is not caching results (Redirects are cached and always little bit hard to invalidate)
I'm using Google Analytics and I'm using filters to remove referral spams. In my web.config file, I also use this:
<rule name="buy-cheap-online.info" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_REFERER}" pattern="*.buy-cheap-online.info" />
</conditions>
<action type="AbortRequest" />
</rule>
I have dozens of these rules and I want to add more. There's this file on GitHub that includes a list of spammers: https://github.com/piwik/referrer-spam-blacklist/blob/master/spammers.txt
I could just keep adding rules to the web.config but it seems messy. What's another way to block referral spam traffic in asp.net so that all the sites in the text file can be blocked and if the file changes I can easily add new sites by reuploading the text file?
Note: I'm not asking for code to be written for me; I just want to know what other options I have.
That's right keep adding rules will be messy and even worse useless, most of the spam in GA never reaches your site, there is no interaction at all so any server-side solution like the web.config won't have any effect.
We can differentiate the spam mainly in 2 categories:
Ghost Spam that never interacts with your page, so any server-side solutions like the web.config or htaccess file won't have any effect and will only fill your config files with.
Some people still hesitate because they think creating filters is just hiding the problem instead of blocking. But there is nothing to block, it is just some guy making fake records on GA reports.
And Crawler Spam as the name imply, they do access your website and can be blocked this way, but there are only a few of them compared with the ghost.
To give you an idea there are around 8 active crawlers while there are more than 100 ghosts and each week increasing. This is because the ghost method is easier to implement for the spammers.
The best way to get rid of all ghosts with just one filter based in your valid hostnames.
You can find more information about the ghost spam and the solution here
https://stackoverflow.com/a/28354319/3197362
https://moz.com/ugc/stop-ghost-spam-in-google-analytics-with-one-filter
Hope it helps.
We are upgrading an ASP Classic website (actually, a virtual directory under a larger website) to ASP.NET 3.5. There will be some legacy directories that remain ASP Classic. Other than that, every .asp file will be replaced by an .aspx file in the same location in the directory hierarchy. We would like not to break old links coming into the site from elsewhere. The website is hosted on IIS 6 (and we have no control over this).
My idea was, in IIS, to replace the usual handler for .asp files, asp.dll, with aspnet_isapi.dll. First question: If I do that, will requests for .asp files then be routed through any custom HTTP modules I create and register in web.config?
Then I would create an HTTP module hooked into BeginRequest that would test whether a request's path (before any querystring) ends in .asp. If so, it would check whether the physical file exists. If not, then I'll use HttpContext.RewritePath to append the "x" to the ".asp". Otherwise, if the .asp file DOES exist, I'll use HttpContext.RemapHandler to switch the handler back to asp.dll so that the file will be processed as the ASP Classic file that it is.
Second question: Will this work? Third question: What do I use as the argument to the RemapHandler method? How do I acquire a reference to an instance of the ASP Classic handler? (If I knew the answer to the third question, I'd have just tried all this on my own!)
UPDATE: OK, I did try it out myself, except that I renamed the remaining .asp files so that their extension is .aspc (ASP Classic), and in IIS I assigned the old asp.dll as their handler. Then, instead of checking whether the .asp file requested exists and remapping to the ASP Classic handler if so, I checked instead whether a file in the corresponding physical location except with the extension .aspc exists. If so, I rewrite the URL to append the "c". This worked! Therefore, the answer to my first question, above, is "yes", and the answer to my second question is "yes, pretty much, except that the part about remapping the handler is unknown". But it would be preferable not to have to change the extensions on all my legacy .asp files, so I am left with one question: Will the original RemapHandler approach work and, if so, what is its argument?
Did you know, that you could handle this quite easily using the web.config file and redirect rules in IIS?
You need to activate the URL Rewrite2 module described here.
This is a really nice feature of IIS, to solve routing problems, see here also for some examples.
Looking at your case, I would do something along the lines of this:
<rule name="execute classic asp if file exists" stopProcessing="true">
<match url="(\w+\.asp)$" />
<conditions>
<add input="C:\Path\To\Your\WebApp\{R:1}.asp" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}c" appendQueryString="true" />
</rule>
<rule name="execute dotnet otherwise" stopProcessing="true">
<match url="(\w+\.asp)$" />
<action type="Rewrite" url="{R:1}x" appendQueryString="true" />
</rule>
I'm not sure if all RegExes here would work for you, but its meant as a start to experiment. The reason to explicitely write C:\Path\To\Your\WebApp\ is, that I didn't find a way to get the base path of the web app as a parameter.
I can't seem to get my head around these rewrite rules for some reason and I was hoping you guys could help. What I want is an outbound rule that will rewrite paths for link, img, script, and input tags.
I want to change this: http://www.mysite.com/appname/css/file.css
To this: http://cdn.mysite.com/css/file.css
So, basically I need to swap the host name and drop the app name from the URL. I've got the pre-condition filters to *.aspx files set already, but the rest seems like Greek to me.
EDIT for clarity
The appname in the URL above is an application in IIS. It's a placeholder for whatever appname happens to be in use. It could be any of over 50 different apps with our current setup. There will ALWAYS be an appname. Perhaps that will make the rule even easier.
The hostname, in this case www.mysite.com, can also vary slightly in terms of the subdomain. It might be www1.mysite.com, www2, etc. Also, just realized that I need to maintain the SSL if there.
So, I guess when it comes down to it, I really just need to take the URL, minus the appname, and append it to the new domain, while respecting the protocol that was used.
Original URL: http(s)://{host}/{appname}/{URL}
Output: http(s)://cdn.mysite.com/{URL}
I assume your website domain is always the same, then this rule should do:
<rule name="CdnRule" preCondition="OnlyAspx" >
<match filterByTags="Img, Input, Link, Script" pattern="^(.+)://.+?\.(.+?)/.+?/(.*)" />
<action type="Rewrite" value="{R:1}://cdn.{R:2}/{R:3}" />
</rule>
<preConditions>
<preCondition name="OnlyAspx">
<add input="{PATH_INFO}" pattern=".+\.aspx$" />
</preCondition>
</preConditions>
EDIT: changed according to clarified question
I assume the subdomain (www, www2, ...)is always there and it has to be ignored in target url.