I need help with config IIS server and Vue 2 application, I just installed vue 2 application with production build on Windows IIS 7 server, and all work fine, only one thing is not working:
When I try to open any page with link "example mysite.com/somepage" which written in vue-router i see 404 error, but if I click on menu link work fine, if you type just main url mysite.com it will open, but any another routes not working!
I think I need to setting my httpRedirect or something like this!
From your information I'm assuming you're using the history mode, here's the one I've been using, and you can reference on here:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
<error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
As noted in the vue-router documentation, in order to use history mode, you need to do the following:
Install IIS UrlRewrite.
Drop a web.config file into the root of the project. See the vue-router documentation for an example web.config file.
Related
In my ASP.NET SPA application I am using web.config to set Rewrite Rules, so I can refresh pages without error (while using Angularjs), but I also would like to redirect to application's homepage, when non-existing page manually entered into url, please advise how should I modify code below to accommodate this:
<rewrite>
<rules>
<rule name="Products" stopProcessing="true">
<match url="^products" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Orders" stopProcessing="true">
<match url="^orders" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Home" stopProcessing="true">
<match url="^home" />
<action type="Rewrite" url="/" />
</rule>
<rule name="List" stopProcessing="true">
<match url="^list" />
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
As suggested by Fedaykin(thanks alot) the following code resolved this issue:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Default.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
Since I work on Single Page Application, in my case path would equal to "/", like this:
<error statusCode="404" path="/" responseMode="ExecuteURL"/>
and then Angularjs routing will take care of the rest.
You can use a 404 error handling to redirect to your homepage (here I´m assuming it´s Default.aspx, but change it to whatever is your home), on your webconfig file put:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="Default.aspx" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Default.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
</configuration>
Also, on your angular configuration use the following to redirect to home:
$routeProvider.
when('/',{'templateUrl' : 'a.html'})
.when('/b',{'templateUrl' : 'b.html'})
.otherwise({redirectTo : '/'})
}
Hope that helps.
I have created code to redirect for non www to www, /index.html to "/", 404 to custom page, I am using IIS server and putting this code in web.config file, have a look, its working fine. But I want to know is it good for SEO ? Or It need any modification ?
Thanx
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="index\.html(?:l)?" />
<conditions>
<add input="{HTTP_HOST}" pattern="example\.com.au$" />
</conditions>
<action type="Redirect" url="http://www.example.com.au/" />
</rule>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com.au$" />
</conditions>
<action type="Redirect" url="http://www.example.com.au/{R:1}" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" responseMode="ExecuteURL" path="/404error.html" />
</httpErrors>
</system.webServer>
</configuration>
Your rules look fine. In general, the idea with making your URLs cannonical is to direct all the link juice to a single cannonical address. In the eyes of Google and such, www.mydomain.com and mydomain.com are two different URLs. Same goes for mydomain.com/ and mydomain.com/imndex.html. The only thing I would add to your rules is a statusCode of 302. This will tell both Google and client`s browsers that you would like them to reffer to the target URL from now on. This way Google will sum all link juice to the target and also clients browsers will not need to be re-redirected with each request.
I am working with an asp.net mvc application. I have the following entry in web.config to handle 404's
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/Error/Error404" responseMode="ExecuteURL" />
</httpErrors>
This works fine for when pages are requested, it redirects to my 404 view. However for missing images it also redirects to the 404 page ie. the response for the image is the 404 page.
As this is a performance issue, is there any way I can alter the above so that only 404 from "pages" and not resources such as images trigger a redirect to the 404 page?
I know this is an year old question, however I just came across the same problem, and I was able to come up with a solution based on what I was using in htaccess.
The below solution basically checks if the file has an image extension, and it isn't a file and isn't a directory. After that it serves up an image file that I use to identify missing images.
<rule name="404 Images" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="^.+\.(jpg|jpeg|png|gif|ico)$" ignoreCase="true" negate="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="/design/images/404.png" />
</rule>
You could disable runAllManagedModulesForAllRequests:
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
...
</system.webServer>
Of course now you're gonna see IIS default 404 page for broken images since static resources will be directly served by the static handler and not going through the managed pipeline.
Using IIS 7.5 in classic mode (as we're using SiteCore) with a WebForms app (.Net 3.5), we have error pages defined as
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
Now, for files of a non .Net type that aren't found when requested , the custom error page isn't being displayed, and a standard 404 status type is returned. If we use a custom error page with a .htm extension (e.g. path="/Error/404.htm"), then it is displayed!
From what I've read the xml is correct, and should work for non .Net file types. I have no section in my web.config. Sounds like something else e.g. SiteCore maybe affecting things - let me know if you need any more info.
404 custom page - works .aspx & non .aspx URLs
Works on GoDaddy Shared Windows Hosting (IIS7 .Net4)
Create a 404.html or 404.aspx file on your local main folder in your shared GoDaddy hosting.
-Web.Config File-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="404.html or 404.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Have you tried adding this 404 page to IIS -> Website properties -> Custom Errors tab, then under 404, point to the web page that you would like to show up when a file is not found?
I installed windows 2008 server integrated iis 7.0
1 day ago, i use windows 2003 and iis 6.0
with windows 2008 server, everything is alright except one thing.
in 2003-iis6 i could use custom 404 pages to handle for url friendly sites.
example i could set custom404.asp as custom 404 pages(execute url)
in 2008, i can't do it.
when i set custom 404 page as /custom404.asp, nothing happens.
in custom error pages it says this is for asp.net
how can i do it?
On the "Error Pages" section in IIS manager select the "Edit Feature Settings..." under the Actions section. Ensure that "Custom error pages" is selected.
the webconfig file below fixed the problem.
i share in case anyone needs
save the code as web.config and move it to main site folder
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/default.asp" responseMode="ExecuteURL" />
</httpErrors>
<rewrite>
<rules>
<rule name="MyURLCleaned" enabled="false" stopProcessing="true">
<match url="^([^])+" />
<conditions>
<add input="{REQUEST_FILENAME}" />
</conditions>
<action type="Rewrite" url="/default.asp?{R:0}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="static">
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>