Cakephp does not work in IIS? - cakephp

I've a issue with Cakephp Version 3.2 on IIS. But, Cakephp Version 2.2 is working well in the same setup environment. Not sure why?
Here's my web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*"
stopProcessing="true">
<match url="^webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(img|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="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>
</rules>
</rewrite>
</system.webServer>
</configuration>
The above content was copied from the Official Cakephp forum.
Whatever we type in URL, I get the below response
Note :
I tried all the related links in SO & I posted this after trying all the provided solutions but none of them worked.
More Information :
IIS Ver - 10
Cakephp - 3.2
I repeat again, Cakephp 2.2 works well.

I would like to answer my own question on how i solved the problem. The problem is not with web.config but the real problem is in .gitignore.
By Default it adds vendor directory to .gitignore. Since it doesn't added to git, those errors were occurred.

Related

Multi language react app on IIS server dont work

I deployed a multi language react app, the default language is French, but when I switch to English language from a button in a header, I have the 404 error.
The link to English is : localhost:port/en
In local environement everything is OK, but when I deploy to IIS server I have the 404 error.
I deployed the app by the command npm run build, and I take the Build folder and put it in the wwwwroot foler
I don'd find any help in the web.
Thanks
Solved.
I installed the URL Rewrite module on the IIS Server, and I added a web.config file with the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Azure Web App Angular Not redirecting to www

I have the following in my web.config
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<rewrite>
<rules>
<rule name="Angular" 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>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
</conditions>
<action type="Redirect"
url="{MapProtocol:{HTTPS}}://www.mydomain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
I have the following in my assets in my angular.json
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
But my app does not redirect.
The issues is i have a App Service managed cert setup for www.mydomain.com
I have two custom domains setup
www.mydomain.com (this one allows me to add the binding to the app service cert)
mydomain.com (is unbound as I cant add a cert)
So I thought I could fix it with the redirect to always go to www. but it does not seem to work
UPDATE
You can RewriterConfig to set url rewrite function in web.config file. More details you can see my answer in anothor post .
PRIVIOUS
The Web Server integrated by App Service cannot have full control, which is one of the attributes of PaaS products.
App Service can only use some functions of IIS. It needs to be configured in the web.config file under /site/wwwroot (that is, the root directory of the project you develop).
All available IIS functions can only be configured through the web.config file.
solution:
• Try to add redirect rule in the web config file. If it fails, you can only use the rewrite feature of the application gateway.
• The following are some documents of Application Gateway about rewrite feature for your reference.
Redirection
Redirect web traffic
Troubleshoot--App service issues

React app route not working after deployed to IIS

I'm new to reactjs and currently facing some issue on IIS deployment for react app.
i execute npm run build and it generate a build folder, i then copy this folder to my IIS.
When i browse the page, im able to view blank page but when i navigate to test route it shows 404.
I've try to add "homepage":"/" or "homepage":"." in my package.json but still the same.
index.html
This is my build structure
Any help is appreciated.
Whenever you deploy a react page to production you will be facing this problem. Please refer to this page: https://inthetechpit.com/2019/06/13/handle-client-side-routes-with-iis-on-page-refresh-react-app/
The issue happens in the server (not IIS only, but all of them). You will be required to install an extension and then, to add a config file to the path of your front end build directory.
The extension to install is here: https://www.iis.net/downloads/microsoft/url-rewrite
the content of the web.config file that should be placed on the front end build directory goes as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
you can create web.config file in public folder and paste below content in it and then
execute npm run build again:
<?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>
To deploy react js app in iis you could follow the below steps:
1)make sure you enabled below iis feature:
asp.net latest version
static content
directory browsing
2)open command prompt as administrator.enter to the react app folder then run below command:
npm run build
which create a build folder in your app folder.
3)open iis then select add site and add folder path build folder and site binding detail:
now, browse your site.
note: make sure you assign the iis_iusrs and iusr permission to the site folder.

prerender.io and using _escaped_fragment_= with angularJs

I have a site that is using prerender.io. Last year it was all working smoothly. This year I had to change the site and I moved it from a .net project to a pure AngularJs application (using yeo angular).
This was done a couple of months ago. What I have recently found, is that prerender.io is not caching my pages anymore.
I found that my web.config has changed. I added this rule:
<rule name="SEO" stopProcessing="true">
<match url="^(?!.*?(\.js|\.css|\.xml|\.html|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.woff|\.ttf|\.m4v|\.svg|\.torrent))(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|Facebot|twitterbot|googlebot" />
<add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="http://service.prerender.io/http://www.kudos-sports.com/{R:0}" appendQueryString="false" />
<serverVariables>
<set name="HTTP_X_PRERENDER_TOKEN" value="****" />
</serverVariables>
</rule>
This is now allowing prerender to cache my site, but it doesn't cache it properly.
If you go to https://www.kudos-sports.com/?_escaped_fragment_= and have a look, you can see that it just pulls in the text that is on the index page.
It doesn't load the ui-view contents :(
Does anyone know why?
Google has already deprecated _escaped_fragment_ support.
Reference:
https://webmasters.googleblog.com/2015/10/deprecating-our-ajax-crawling-scheme.html
https://medium.com/finnovate-io/googlebot-no-longer-picking-up-content-in-prerender-io-pages-ae21d9710459

IIS 6.0 Won't Pass Bot Requests to Prerender.io

We have a website coded with AngularJS. Since much of the site is generated via javascript, search engines can't index the pages. So, we have setup Prerender.io to index our site. It does that fine and I can view the rawhtml from their site.
If I enter the following into a browser, Prerender.io will display the rawhtml correctly:
http://service.prerender.io/http://www.swiftlearning.com/?_escaped_fragment_=/login
The problem is that I can not get IIS 6 to send the bot requests to Prerender.
When I take this URL: http://www.swiftlearning.com/#!/login and replace the #! with ?_escaped_fragment_= resulting in http://www.swiftlearning.com/?_escaped_fragment_=/login
IIS returns the initial web site page and displays the following URL:
http://www.swiftlearning.com/?_escaped_fragment_=/login#!/home
I have setup Wireshark to capture the traffic. It shows that the request comes in and then the response comes from the website, not prerender.io.
I created a web.config file (with what I have already found on StackOverflow) with the following configuration.
<?xml version="1.0"?>
<configuration>
<system.web>
<httpProtocol>
<customHeaders>
<add name="X-Prerender-Token" value="dTaPu5H97XTS618Y8edm" />
</customHeaders>
</httpProtocol>
<httpModules>
<add name="Prerender" type="Prerender.io.PrerenderModule, Prerender.io, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null"/>
</httpModules>
<rewrite>
<rules>
<!--# Only proxy the request to Prerender if it's a request for HTML-->
<rule name="Prerender" stopProcessing="true">
<match url="^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|twitterbot" />
<add input="{QUERY_STRING}" pattern="_escaped_fragment_" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="Redirect To Index" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.web>
</configuration>
I hope that I haven't confused the issue with my explanation. Any help will be appreciated.
Thanks,
Dana
Well, it turns out that IIS 6 does not handle redirects. Redirects became possible with IIS 7. So, it boils down to upgrading our server, which for various reasons is highly suggestible, or some hack.
Thanks for looking at the question.
I can not select this as the answer until tomorrow.
Dana

Resources