Why Does URL Redirect Add Parameters to Root Directory of Destination DomainURL? - url

[Edit] is there anything I can add to my question so that I can get assistance?
Please help me work this out.
I am trying to use a web.config redirect from a dynamic page on one domain to a static page on a new domain. Here is the code I'm trying (I've tried many other variations too without success):
<rule name="69" stopProcessing="true">
<match url="^product-details.php?aaaaa=B086RX7LW1&bbbbb=Moleskine%20Cover%20XL" />
<action type="Redirect" url="https://www.leatherjournals.com/collections/notebook-leather-covers/products/leather-refillable-journal-cover-for-moleskine-cahier?
variant=42204410183930" redirectType="Permanent" />
</rule>
So the page should redirect to:
https://www.leatherjournals.com/collections/notebook-leather-covers/products/leather-refillable-journal-cover-for-moleskine-cahier?variant=42204410183930
But it actually redirects to
https://www.leatherjournals.com?aaaaa=B086RX7LW1&bbbbb=Moleskine%20Cover%20XL
That page shouldn't have parameters. The root page is shown instead with the parameters added to the url (it is a full url, the 'bbbbb=' doesn't show properly in my question).
Any advice please? Thanks in advance.

Related

IIS 301 Redirect from one Controller to another (including parameters) ASP.NET MVC

I renamed one of my controllers and now want to do a HTTP 301 to the new URL. I prefer doing it from IIS so I don't pollute my RouteConfig. I also want to include any parameters included in the redirect.
I'm trying to achieve all of the following:
site.com/old --> 301 site.com/new
site.com/old/ --> 301 site.com/new/
site.com/old?foo=bar --> 301 site.com/new?foo=bar
etc
This is what I have so far but I can't get it to work:
<rule name="Redirect Old to New" pattern="ECMAScript" stopProcessing="true">
<match url=".*\/old.*" />
<action type="Redirect" redirectType="Permanent" url="/new/{R:0}" />
</rule>
The issue appears to be with your RegEx. A URL in this context will never begin with a / and you should always match the beginning of the string ^. Also, you need to define what to capture in order to supply the end of the redirect URL.
<rule name="301 Redirect Old to New">
<!--
matches /old
matches /old?foo=123
matches /old/?foo=123
matches /old/older/oldest?foo=123
doesn't match /oldee/whatever
-->
<match url="^old(?:/|(?=\?)|$)(.*)"/>
<action type="Redirect" redirectType="Permanent" url="new/{R:1}"/>
</rule>
Also, for SEO purposes I would say you are shooting yourself in the foot with your second option. You should either always use a trailing slash or never use one in your redirect. Pick one and then be consistent so all of your landing URLs are the same.
While there is nothing wrong with using IIS for 301 redirects per se, you should be sure you are sufficiently skilled at creating regular expressions if you take this approach. It also helps if you have a regular expression tester utility to ensure what you are writing works the way you expect.
There is a great tutorial to learn regular expressions here: http://www.regular-expressions.info/tutorial.html

Redirect URLs with sitecore at the end

I would like to ask for your help about redirect with URLs which contains sitecore at the end.
What I want to do is that if my requested URL contains "sitecore" at the end I want redirect this to hostname.
e.g. www.mySiteName.com/sitecore redirect to www.mySiteName.com.
So I created simple pattern for this as first:
then I changed configuration above to only (.*)(sitecore)$.
But when I request URL what I get is:
www.mySiteName.com/sitecore/service/nolayout.aspx?item=%2fsitecore&layout=%7b00000000-0000-0000-0000-000000000000%7d&device=Default
instead www.mySiteName.com.
I dont understand why this behaves like this.
Appreciate your help
Thanks
I think you are over complicating your condition and potentially redirecting to the wrong reference.
Try
<conditions>
<add input={URL} pattern="(.*)sitecore$" />
</conditions>

IIS hosting ASP.NET MVC site gives http 404 for urls containing 'web.config'

Requesting a page from IIS (hosts ASP.NET MVC 3 site) with url containing web.config gives 404 error. Urls with app.config have no problem. Local Visual Studio development server has no issues with this type of urls.
1 - What are any other special words other than web.config, being handled this way by IIS?
In request filtering page/hidden segments tab this is the current state:
I guess these are not special words, because IIS handles words like bin, App_code etc without a problem.
Answer: I guess these are the words being handled by IIS this way. So these are the default words I think and this list is configurable (new items can be added to this list).
2 - Are there any quick fixes (like by web.config modification) to handle urls with these special words?
Btw, I am not trying to serve the web.config file. Url format is : www.mysite.com/es/web.config/1
This is part of the IIS configuration under the Request Filtering section:
You can add/remove filters.
However, I do believe this is a really bad idea to remove web.config from it.
http://www.iis.net/configreference/system.webserver/security/requestfiltering
Cause:
As you already shown a snapshot of IIS configuration. These are reserved folder & files in .Net application, so IIS want to preserve those for security.
URLs which contain these strings as returned as 404 response only if these comes in before ? AND exactly between 2 slashes /../ OR at last. Eg: www.example.com/bin/anything.ext OR www.example.com/folder/sub/web.config
IIS match these string anywhere coz, web.config can we at any directory level.
If anything is with those string are there THEN page will be served by IIS. Eg: www.example.com/bin-folder/anthing.ext OR www.example.com/sub/bin.html OR www.example.com/-web.confing/page.aspx are OK.
I recommend to use some other words with these strings OR use at end of URLs with extensions, so that it will not come between two slashes.
Eg: www.example.com/en-web.config/1 OR www.example.com/en/1/web.config.aspx
Even then I have one Tricky Solution:
If you really need these strings exactly without other words in URL THEN I recommend to use URL-ReWrite.. This may not be quick at whole but except 2nd step its quick and handy, coz second step depends on your application.
1- Add this rule in IIS at top level:
regexp match: (/web|^web)\.(config$|config/) //OR as your requirement
re-write to: handler.aspx?url={REQUEST_URI}
<rule name="web-config" stopProcessing="true">
<match url="(/web|^web)\.(config$|config/)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="handler.aspx?url={REQUEST_URI}" appendQueryString="false" />
</rule>
2- In handler.aspx (or in any other language page) check the url GET variable and respond accordingly.Request.QueryString("url")
Do it carefully coz here you are controlling security.
I suggest to include the actual page content to response in handler.aspx or handler.php only rather then redirecting etc.
Before including content verify URL first(by regular expression etc.), and include content hardcoded, do not take any part of URL in to variable and use that variable in response-inclusion-code.
3- After that at last from IIS manager, In a specific website go to request filtering->hidden segment tab and delete the desire string. Eg: web.config. This step can be done by web.config also:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
<hiddenSegments>
<remove segment="web.config" />
</hiddenSegments>
</requestFiltering>
</security>
Now, IIS will serve the page and your handler page will show the output with exact same URL in user browser.

Umbraco rewriting URL based on old page

I just recently started working on a project that involves Umbraco. So, I am no expert on it (not even close). Please help.
The issue is, we had a page on our site that was example.com/careers.aspx. This page had the old content.
We have now redesigned it and moved the cotent "INTO" careers "folder". So, now it should work as example.com/careers/en/home.aspx.
However, when we go to that URL, it rewrites it as example.com/careers.aspx/en/home.aspx.
I looked for any rewrite config files but there are no rules (in the file; not sure about DB).
can someone please help? I am not sure what is happening here.
For additional information, when I look at "Properties" for /careers/en/home page then it shows "Link to Document" as "/careers/en/home.aspx".
Thanks
Presumably you are using Umbraco v4? In the web.config for a Umbraco v4 there is a umbracoReservedUrls appSetting key. You could add your path in here and Umbraco will essentially ignore rewriting it when it is requested.
The rewrite configuration is actually in config/UrlRewriting.config and this will allow you to control custom rewrites.
In the web.config you can created rewrite rules for the required pages.
In the < system.webServer> section create a < rewrite> < rules> section and then add for each page as required.
Would be something like this...
<rewrite>
<rules>
<rule name="RewriteCareers" stopProcessing="true">
<match url="careers.aspx" />
<action type="Rewrite" url="careers.aspx/en/home.aspx" />
</rule>
</rules>
</rewrite>

Redirect subdomain request to subdirectory in MVC

So, I currently have a simple MVC web site sat on www.mysite.com and an installation of BlogEngine in a BLOG folder on the root.
my question is how, in code, can I redirect a hit on sub.mysite.com to display the blogengine site in the BLOG folder?
The sites are currently hosted with WinHost who have suggested using a simple VBScript (seen here). This is fine but I can't for the life of me figure out where to put it within the MVC site. The link says the "default" document, but is that wihin the body/head? everything I have tried hasn't worked.
I know things are all working on the host side of things as hitting sub.mysite.com simply displays the MVC site as it should.
I have also read about the rewrite module but I feel this isn't an option because of limitations with my host.
Any help would be super awesome!
EDIT: Following Dan Atkinson's post below I have accessed the IIS7 Rewrite Module and created the following rule:
Input URL path after ‘/’ Matches (.*) Redirect http://www.mysite.com/blog/{R:1} (Stop processing = true, entry type = local)
{HTTP_HOST} Matches the Pattern ^blog.mysite.com$
{REQUEST_URI} Matches the Pattern /blog
the XML for this rull looks like this:
<rule name="blog.mysite.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^blog.mysite.com$" />
<add input="{REQUEST_URI}" negate="true" pattern="/blog" />
</conditions>
<action type="Redirect" url="http://www.mysite.com/blog/{R:1}" />
</rule>
This still isn't working though and is still just defaulting to the root site..I feel we are close though! Thank you for all your help so far!
Do you have IIS7? If so, it may be better to do this as a redirect there instead. It will also perform better as well as the request won't even come into your MVC application.
Edit:
Someone else on WinHost posted this which may provide some help.

Resources