I am trying to remove the web folder in the URL of my Yii2 web application hosted on windows server.
I want my application to be accessed at http://example.com instead of http://example.com/web
I have managed to enable pretty URLs using the code below.
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
how do I achieve this?
These instructions are not for IIS but for Apache, you configure the Document root to the web folder.
https://www.yiiframework.com/doc/guide/2.0/en/start-installation#recommended-apache-configuration
Or maybe this answer will help guide you in the right direction.
IIS document root in subfolder
The simplest and direct solution for your requirement is to follow exactly the regarded IIS configuration in the official documentation.
In other words, you have to create a virtual host (it may be called Sites in IIS) on your iis that points to the web directory of your project and place web.config file with the code regarded in the documentation there.
Hint: you may need to edit your Windows hosts file to allow accessing this host locally.
It's actually very easy on IIS when using Plesk.
Just change the document root to include the web folder.
Related
I have sucessfully deployed nodejs app in azure. when I navigate to **https://my-app/xyz ** refresh page I see, You do not have permission to view this directory or page.
I tried to edit web-config but still it doesn't work. I am not sure If this is security issue or node.js is not able to serve anything for this route but on my local machine If I do refresh It doesn't show this issue. Thje picture above contains the directory structure and /client has Angular compiled files.Thank you
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteRules" 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="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
I have experienced this error. I suppose you access the website via a virtual directory.
Make sure you have set the correct virtual directory for your app.
It should be the virtual path /xyz, Physical Path site\wwwroot\yourcustomfoldername. It will be something like this,
Make sure the Physical Path match the actual root directory of your web app in KUDU site.
IIS 10 is throwing the error
404 File or directory not found
Only when I try to access the url with subfolder path like this:
http://myserveraddress.com/object/181
So it works without the subfolder. The subfolder path is used by Angular to query a rest interface so there is no physical folder path behind it, just used for querying behind the schene.
This actually works when running on localhost but not on the server.
Is it possible to configure IIS such that it allows any url path even though the physical folder path does not exist?
This loos more like a handler configuration issue, and also if your server is a brand new server may be you haven't installed the handlers which is supposed to process your request, if i have to take a request if you haven't configured the rest handlers required it is goind to the static file handler which tries to look for a folder in the request url path and throw an error, if you already have a setup running, check all the handlers and pre-requisites installed there and mimic the setting over in the new server as well
The solution was to add this to the Angular client web.config file
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes" 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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
More detail can be found here Get Angular2 routing working on IIS 7.5
I'd like to start by saying I am very (VERY) new to Azure. I have just publish an AngularJS app and I've come across an irritating issue.
When publishing the app from visual studio the first time around, it placed the files inside site\wwwroot. This was fine because I then just changed the virtual path to look at the www subfolder.
So the new setting makes / equal to site\wwwroot\www
This is because the code for my site actually sits within this www folder. Everything worked! Great!
However, the next time I did a publish, the whole site was then places within site\wwwroot\www, meaning that to get to my index page I had to go to site\wwwroot\www\www.
For some reason by defining the 'Physical path relative to site root', it changes the whole publish path. This does kind of makes sense, but is there anyway around this issue? Possibly a different practice or setting I haven't come across yet.
Any tips or advice would be greatly appreciated!
Thanks in advance.
Since you have mapped / to site\wwwroot\www, your later publish would be applied to site\wwwroot\www. Per my understanding, you could directly deploy your web content under www to site\wwwroot via ftp tools, etc. Or you could use URL Rewrite instead of changing the virtual path for /. And your rewrite rules under the web.config file as follows:
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="hide www sub directory" stopProcessing="true">
<match url="^www/(.*)"/>
<action type="Redirect" url="{R:1}" appendQueryString="true" redirectType="Permanent"/>
</rule>
<rule name="rewrite to sub directory">
<match url="^(?!www)(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="www/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Note: The we.config file is under site\wwwroot.
TEST:
Kudu
For accessing the index.html, you need to access https://brucewebapp.azurewebsites.net/www/index.html. Using the url rewrite rules, you could just access https://brucewebapp.azurewebsites.net/index.html as follows:
I have a website that I host on azure. I recently bought an SSL and configured it. Now users can visit my site by typing in either http://example.com or https://example.com.
What I want is for users who type in the former to be automatically redirected to the latter while also keeping anything after the .com
So if a user types in http://example.com/about they will be redirected instead to https://example.com/about.
After some reading, I've come across this code that seems to do what I want
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to https”>
<match url=”(.*)”/>
<conditions>
<add input=”{HTTPS}” pattern=”Off”/>
<add input=”{REQUEST_METHOD}” pattern=”^get$|^head$” />
</conditions>
<action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}”/>
</rule>
</rules>
</rewrite>
</system.webServer>
But before I add this to my web.config file I have a few questions.
What is the IIS url rewrite module? IIS Rewrite and is it required to be installed on my azure hosted websites before I upload my new web.config file.
How can I also include removing www from my URL when a user enters it. For example if a user types in www.example.com they should be redirected to https://example.com instead. The reason that I want this is because in my google search console I've told google to display URLs as example.com rather then www.example.com
and finally, will this code do what I'm looking for? Is there a more professional way to achieve this? What are the benefits. I should note that my sites are asp .net web forms. I know MVC has routing options but that is not an option for me.
Edit : I don't think How to force HTTPS using a web.config file solves my issue because I don't even know if I can install the URL Rewrite module since I am not hosting IIS myself. Does azure give you access to the IIS settings? I am unfamiliar with azure details.
The Microsoft URL Rewrite Module for IIS enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find.
This module is pre-installed for Azure Web App, as shown when inspect the applicationHost.config of the Azure Web App in Kudu.
Hence, you do not need to worry about the availability of the module for Azure Web App.
The URL Rewrite configuration to enforce HTTPS redirection for Azure web app is the simplest way to achieve what you intend. Your above configuration will apply
only if the request method is either HTTP GET or HTTP HEAD. The below configuration will not have such limitation.
<system.webServer>
<rewrite>
<rules>
<rule name="Force HTTPS Redirection" enabled="true" stopProcessing="true">
<match url="^$" ignoreCase="false"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
I would add one last thing. Assuming you are running on Azure Web Apps, they have various probes to your site for warm up and initialization. You probably don't want these probes to also be redirected, otherwise, you may have some issues when you restart or use Azure's swaps feature for stuff like blue/green deployments. These probes would then be return with a 301/302 rather than actually hitting your site (and Azure doesn't actually follow the redirect)
More examples https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples
<rule name="Redirect to non-WWW" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com$" />
<add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" /> <!-- IIS Application Initialization Warmup -->
<add input="{HTTP_USER_AGENT}" pattern="SiteWarmup" negate="true" /> <!-- Azure WebApps Warmup Request -->
<add input="{HTTP_USER_AGENT}" pattern="AlwaysOn" negate="true" /> <!-- Azure WebApps AlwaysOn Probes -->
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://example.com/{R:1}" />
</rule>
<!-- Redirect to HTTPS Version -->
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="SiteWarmup" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="AlwaysOn" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
I'm reading through the documentation, and don't see what i'm looking for.
This new build is going to run on a staging --> prod set up. On the prod side, I'm hoping to the have the admin login only available to local host. This way you have to be logged into the server to access the admin panel.
I'm assuming i need to make the web.config adjustments, but how do i ensure that only http://localhost/ works?
Try installing URL Rewrite on the web server and adding the following rewrite rule to your web.config system.webServer section. This should cause IIS to intercept any URLs under /admin and return a 403 if not on a URL local to the server. You might also need to adapt the URL match or add additional rules for other Kentico admin paths (e.g. CMSAdministraton.aspx etc.).
<rewrite>
<rules>
<rule name="Block Remote Access to Admin" stopProcessing="true" patternSyntax="ECMAScript" enabled="true">
<match url="admin(/|$)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{REMOTE_ADDR}" pattern="localhost" ignoreCase="true" negate="true" />
<add input="{REMOTE_ADDR}" pattern="127.0.0.1" negate="true" />
<add input="{REMOTE_ADDR}" pattern="::1" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="403" statusDescription="Forbidden" statusReason="Access to this URL is restricted"/>
</rule>
<rules>
</rewrite>
Add custom code in Admin/CMSAdministration.aspx.cs to grant localhost only.