cakePHP and IIS8.5 : HTTP Error 404.0 - Not Found - cakephp

When I browse to localhost/admin/videos/view/1 I get the page I want. I also want that page to show when I browse to localhost/videos/view/1.
But it gives me error message :
HTTP Error 404.0 - Not Found
Detailed Error Information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://{my-ip}/app/webroot/videos/view/1
Physical Path C:\inetpub\wwwroot\{my-project}\app\webroot\videos\view\1
Logon Method Anonymous
Logon User Anonymous
These are my rules in the web.config file :
<rule name="Rewrite requests to test.php" stopProcessing="true">
<match url="^test.php(.*)$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/test.php{R:1}" />
</rule>
<rule name="Exclude direct access to app/webroot/*" stopProcessing="true">
<match url="^app/webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, fonts, vid, favicon)" stopProcessing="true">
<match url="^(img|css|files|js|fonts|vid|favicon.ico)(.*)$" />
<action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
Update :
It has something to do with
<match url="^(img|css|files|js|fonts|vid|favicon.ico)(.*)$" />
When I cut the vid| (that is the directory of my videos) it shows localhost/videos/view/1.
But then I have the problem that it doesn't load my video.

What I've done to resolve this:
1 I deleted the |vid inside
<match url="^(img|css|files|js|fonts|favicon.ico)(.*)$" />
2 I replaced the vid folder inside my webroot to the files folder because that folder is standard there.
3 I changed the src to the video in my view
<source src="/files/vid/...

Related

Redirect to root page on 403 response

I have a React App hosted on IIS. If I access an existing directory, such as <app_url>/static/, it returns a 403 response since there's no permission on that directory. I'd like to redirect the user to my root page (~/).
I have tried this:
<httpErrors>
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" prefixLanguageFilePath="" path="/" responseMode="ExecuteURL" />
</httpErrors>
This kinda works, it does return the root page, however, it tries to download the React bundles from /static/ instead of '/' only.
What can I do here?
I used this rule and it worked:
<rewrite>
<rules>
<rule name="Redirect Static" patternSyntax="ExactMatch" stopProcessing="true">
<match url="static" />
<action type="Redirect" url="/" redirectType="Found" />
</rule>
</rules>
</rewrite>
(Thanks to #samwu)

No route registered for static file in Azure App Service

I have a Azure App Service that runs a ReactJS application. In the release pipeline I extract a zip file that contains my Cypress test results.
When I navigate to my Kudu console I can find the correct folder and files in my PS D:\home\site\wwwroot\e2e\mochawesome-report> folder. But when I navigate to
a video:
https://exampleUrl/e2e/mochawesome-report/video/onboarding.spec.js.mp4
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
But when I navigate to: https://exampleUrl.azurewebsites.net/e2e/mochawesome-report/screenshot/customer-card.spec.js/Customer card action tab -- can click on the account tab (failed).png
I can view the image.
Is there some configuration needed to view static files?
##EDIT##
Added my web.config:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I'm pretty sure I found this somewhere on the web.
Something else I noticed. I can now open a .html and .css, .js and .png files but no .json, .woff, .woff2 and mp4.
You need to define file extensions to your web app.
Add these lines to your web.config, below your </rewrite>, then restart your Web App:
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
To add other extensions (like json):
<mimeMap fileExtension=".json" mimeType="text/plain" /
The result would be:
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".json" mimeType="text/plain" /
</staticContent>

IIS Redirect all request on root

I have reactjs application with react router. I dont want to use hash history and I encountered the issue with refreshing page creating 404 error (react-router is not loaded when refreshing and browser wants to fetch non-existent content thus 404). I found some solution and I want to redirect every request to root so server always fetch index.html with import tags first.
My folder structure is simple:
ROOT/
-- index.html
-- static/
-- js/
-- main.js
-- css/
etc...
I have this web.config rule found on this site:
<rewrite>
<rules>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
This works very fine with URLs on first folder path, I mean all request like /items, /contact are good. But requests like /items/detail are broken because browser is looking into items folder and not into document root. Also very important thing is that my webpack generate index.html script tags in this manner: <script type="text/javascript" src="./static/js/main.js">.
Is it possible that src attribute is wrong because of that ./? How can I tell server (IIS 10) "hey don't look anywhere else but into document root?"
Thanks guys.
This is a solution I found were I have some paths I still want to handle by my IIS but the rest I want react to take care.
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="^(.*)$" />
</rewriteMaps>
<rules>
<rule
name="redirect all requests"
stopProcessing="true"
>
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add
input="{REQUEST_URI}"
pattern="/someOtherResourceIstillWantIIStoHandle(.*)$"
negate="true"
/>
<add
input="{REQUEST_FILENAME}"
matchType="IsFile"
negate="true"
/>
<add
input="{REQUEST_URI}"
pattern="/resourcecentre(.*)$"
negate="true"
/>
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

ASP.net WebAPI ignoring web.config?

I am setting up a web.config in wwwroot to redirect all requests to index.html for angularjs to handle. This excludes existing files and folders and anything from /api.
The problem is, it's not working that way. I simply get blank pages for anything where a file does not exist.
Here is my web.config:
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
<rewrite>
<rules>
<rule name="IndexHomeRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I can't figure out any reason for it to still be trying to load the files instead of redirecting them to index.html
I am using .NET Core RC2 and I have static files and default files set to be used. I am using VS2015. I set the project up as a WebAPI from the beginning. Not empty.
You can use Microsoft.AspNetCore.SpaServices:
app.UseMvc(options =>
{
options.MapRoute("Api",
template: "api/{controller}/{action?}/{*path}",
defaults: new { controller = "Home" });
options.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
});

Url Rewrite for angular urls

I have Angular URL e.g "www.mycompany.com/employee/{78}" .
I want to rewrite this url as if i click on this employee and try to open it in new tab its using base url i.e. "www.mycompany.com/index.html/employee/78".
<rule name="main rule 2" stopProcessing="true">
<match url="^index.html/employee/[0-9]+$" />
<action type="Redirect" url="/employee/{78}" appendQueryString="true" />
</rule>
Here my question is how i can use the querystring ?? i.e. in this case employee id while rewriting the URL. Right now i have put the constant 78 but instaed of any constant i want to refer to "[0-9]+$" this value.
Found following answer. Need to put parenthesis for ([0-9]+) to use {R:1}.
<rule name="main rule 2" stopProcessing="true">
<match url="^index.htm/employee/([0-9]+)" />
<action type="Redirect" url="/employee/{R:1}" appendQueryString="false" />
</rule>

Resources