I'm trying to map a URL like this:
www.domain.com/some-page.cfm?coid=1
to be more user-friendly like this:
www.domain.com/some-page/company-name
or
www.domain.com/company-name
I've tried over and over using URL Rewrite in IIS and can't for the life of me get it to work.
Any help would be appreciated!
I think you may actually want to do the opposite... use IIS to map /abc.htm requests to /?id=abc, right? (For the rule you are requesting, I recommend writing that using ColdFusion.)
Here's an IIS rule that we use in order to not expose ".cfm" in our blog URLs. Anything URL parameters after "/blog/" in the URL is available to ColdFusion as URL.WebPath. Additional URL parameters are retained. If you modify this, I recommend matching a URL patterns (like "blog/" or "/detail-") so that only specified URLs are rewritten.
<rewrite>
<rules>
<rule name="CFMBlog" patternSyntax="ECMAScript" stopProcessing="true">
<match url="blog/(.*.htm)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SCRIPT_FILENAME}" matchType="IsFile" negate="true" />
<add input="{PATH_INFO}" pattern="^.*(blog/index.cfm/).*$" negate="true" />
</conditions>
<action type="Rewrite" url="/blog/index.cfm?WebPath={R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
On the ColdFusion-side, you'll want to analyze the URL and ensure it's in the proper format. You don't want to have both versions of the URLs responding for fear of SEO duplication (unless you set up URL canonicalization). I'm my experience, it's best to serve a 301 Permanent Redirect to a lowercased, dash-separated ".htm" version of the URL.
In your CFM pages, you'll need to add some logic to check whether .htm is in path_info, URL.COID exists in the original request and URL.webpath does not. Depending on your situation, you could perform a 301 to redirect to the HTM version of the URL so that both search engines & users are aware of the new URL.
Have you taken a look at this? IIS URL Rewrite not working with query string
Or if you want to do this with pure ColdFusion without IIS, how about this?
some-page.cfm
<!--- Test for query string params --->
<cfif StructKeyExists(url, "coid") and url.coid eq 1>
<cflocation url="/some-page/company-name" addtoken="no">
<cfelse>
<!--- Other processing here... --->
</cfif>
Related
We have a requirement for redirecting couple of webpages to different URLs of our website. For instance:
https://old-domain/-->https://new-domain/;
https://old-domain/promotion/campaign-->https://new-domain/;
https://old-domain/about-us-->https://new-domain/about-us/company;
https://old-domain/about-us/awards-and-recognitions-->https://new-domain/about-us/company;
https://old-domain/careers-->https://new-domain/careers/;
https://old-domain/careers/apply-for-a-job-->https://new-domain/careers/;
https://old-domain/claim-status-->https://new-domain/;
https://old-domain/contact-us-->https://new-domain/contact-us;
We need generic rewrite rules for the above, where
we either redirect to the desired destination URLs (manually hard-coding them in the rewrite rules)
or
add a single redirect rule for the first URL and regex expression to skip the rest (since the rest can be managed internally within the CMS but not the first)
I would do it via IIS Rewrite Rules in the web.config (unless the client requires to be able to edit those in the UI)
I would add a rule for each Url (or maybe combine a few where possible)
They could look like this:
<rewrite>
<rules>
<rule name="Redirect old domain" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="[www.]oldDomain.com$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.newDomain.com/{R:0}" />
</rule>
....
</rules>
</rewrite>
Edit: Updated the rule above so that it will cater for any page on the old domain and will redirect to the same page of the new domain.
Examples:
www.olddomain.com will redirect to www.newdomain.com
www.olddomain.com/about-us will redirect to www.newdomain.com/about-us
Now, you can create the /about-us page in Sitefinity and make it a redirect page and redirect to wherever you want.
Looking for a method we can use in our ASP.NET MVC-5 IIS-8 site to return a 410 error response (gone) based on a list of phrases contained in the querystrings.
Why? We're receiving a few hundred daily junk hits from reputable bots (e.g., Google, Bing, Yahoo) for ridiculously named pages that we've never had on our site. I'm thinking that for most of these pages I can test if a given key-phrase exists and, if it does, return the 410. I'd like to return the 410 to tell the bots they can remove their listing permanently thereby providing a gradually improved SEO environment.
Here's a few examples of URL's we're receiving with the key-phrase I would test for in bold.
https://www.example.com:443/apple-touch-icon-precomposed.png
http://ww.w.example.com:80/zdjqhhmtkatt.html
I know this is very do-able with .htaccess in other programming environments so I'm hoping there's also an elegant solution for ASP.MVC.
You can do that with URL rewrite module. The rule in your web.config should be like that:
<rewrite>
<rules>
<rule name="410response" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="apple-touch" />
<add input="{REQUEST_URI}" pattern="zdjqhhmtkatt" />
</conditions>
<action type="CustomResponse" statusCode="410" statusReason="System unavailable" statusDescription="Gone. The requested resource is no longer available." />
</rule>
</rules>
</rewrite>
I'm using IIS URL rewriting module to mask my internal URLs with friendly URLs through rewrite maps and Rewrite rules (not redirection). This is my rewrite map:
<rewriteMap name="HashTest">
<add key="/nohash" value="/nohash.aspx" />
<add key="/hash1" value="/hashtest.aspx#hash1" />
</rewriteMap>
and this is my rewrite rule:
<rule name="Rewrite rule1 for HashTest">
<match url=".*" />
<conditions>
<add input="{HashTest:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
This is working for URLs with no hashtags, so every time I query www.mysite.com/nohash it shows me content from www.mysite.com/nohash.aspx with our changing the URL on the browser.
Now when I try to rewrite to a URL containing a hashtag I get a 404 error, for instance www.mysite.com/hash1 should just show me content from /hashtest.aspx#hash1 but I just get a 404.
Now if I change my rule action type to Redirect it does make redirection successfully, so I don't know why it doesn't work with rewrite.
I know hashtags are not sent to the server on the request, but it would make sense if my rewrite map was backwards, like <add key="/hashtest.aspx#hash1" value="/hash1" />.
Any insights on why redirection works with hastags but rewrite doesn't?. I'm not married to IIS redirection, if you have another module or approach I can use it's very welcome
The part after the hash sign (officially called the fragment identifier) is a client-side only part of the URL. It's never send to the server. That's why it won't work for rewrite but only for redirects. The rewrite rule will match but IIS will actually try to open a file called hashtest.aspx#hash1 (i.e. a file with the extension .asp#hash1). This file won't be processed as a normal ASP page as the extension is not linked to ASP.NET. And most likely it's content won't even be displayed at all as IIS is by default configured to only allow request for known extensions.
I want to create a rule to redirect query to a page (which doesn't exist) to another
Example:
http://www.example.com/en/page.asp?id=2&...
to
http://www.example.com/en-US/newpage.asp?id=2&...
I use this rule:
<rule name="Redirect" stopProcessing="true">
<match url="page\.asp\?(.+)$" />
<action type="Rewrite" url="newpage.asp?{R:1}" />
</rule>
But this doesn't work... I got a 404 error...
What is my mistake?
Thanks
URL Rewrite's Rewrite action is only for rewriting the page URL that
gets displayed on the browser but it expects the original page to
exist on the server. For your case, you need a Redirect action.
The regex needs to be changed to reflect "en-US" in the final URL.
Try this code instead:
<rule name="Redirect" stopProcessing="true">
<match url="en/page\.asp\?(.+)$" />
<action type="Redirect" url="en-US/newpage.asp?{R:1}" redirectType="Permanent"/>
</rule>
The permanent redirect helps makes your website SEO (Search Engine Optimized) preventing search engine bots to index the old URL (and hence not splitting page ranks between the 2 URLs).
I want to ensure that anybody who goes to http://example.com/* gets automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).
Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.
The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.
Alternatively, here's a couple of techiques for redirecting to a canonical URI:
http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.stevenhargrove.com/redirect-web-pages/
Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.
I have another solution for you:
<rule name="Canonical domain name" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>