IIS Symfony 4, 404 Error - symfony

I am trying to make works symfony 4 demo application on my environemnt.
I am using IIS with CGI and rewrite module. I can't have access to the home page of the demo, I think my IIS configuration is not well configured. Is there a standard web.config for symfony 4 and IIS? I didn't find anything.

I finally make it works. I convert the rewrite rules of the htaccess to IIS xml.
It looks like below. Hoping it will help others.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Related

When refreshing a page developed by nextjs error occurred

I have developed a project by nexjs which their backed is IIS and all these are working properly.
I have an URL address like this :
dastshafa.ir/product/2/آویشن
It works well until I wasn't refreshing a page.
the browser throws an error:
404 - File or directory not found.
I was applied this web.config snipped:
<?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="{QUERY_STRING}" pattern="^product/\[0-9]{1,}/\.*$" />
</conditions>
<action type="Rewrite" url="dastshafa.ir/{C:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But my problem is not fixed yet.
How can I fix it?
It seems it was correlated to IIS URL rewrite issues. fortunately, I succeed to do this using this snipped, that is persist in a web.config file:
<?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="{PATH_INFO}" pattern="\/product\/(\d+)\/.*" />
</conditions>
<action type="Rewrite" url="product/[productId]/[productName].html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
thanks to https://dnnsupport.dnnsoftware.com/hc/en-us/articles/360005303894-Creating-a-rewrite-rule-with-IIS-and-the-web-config

wordpress installed in cakephp subfolder on iis window server

i have installed cakephp 2.6 version on microsoft window server 6.2 IIS service 8.5
in that i have installed wordpress blog in sub directory under app folder
|_ cakePHP
| |_ app
| |_ blog
| |_ lib
| |_plugins
every thing working correctly in cakephp app also wordpress blog is also working
fine if we hit baseurl/blog/
index page appeared correctly.
But when we change the setting in wordpress blog parmalink setting and make prety url like
https://www.baseurl.com/blog/hello-world/
it give 404 error but its working with plain url like
https://www.baseurl.com/blog/?p=1
but i need the prety parmalink URL like
https://www.baseurl.com/blog/hello-world/
i search many article for this also find many but no answer is working with the window server with cakephp
as you all are aware .htacces is not work on iis 8 so i create web.config file in root folder of cakephp
|_ cakePHP
| |_ app
| |_ blog
| |_ lib
| |_plugins
| |_web.config
code of root folder/above web.config is
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!--# Exclude requests already going to /subfolder to avoid an infinite loop-->
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^blog.*$" />
<action type="None" />
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
<rule name="Exclude direct access to app/webroot/*" stopProcessing="true">
<match url="^app/webroot/c$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(geet_jewellery,img, css, files, js, favicon)" stopProcessing="true">
<match url="^(blog|buyanddelight|crm_geet|geet_jewellery1|geet_jewellery|img|css|files|js|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>
</rules>
</rewrite>
<httpErrors errorMode="Custom" defaultPath="C:\Inetpub\wwwroot\Indexhome_.htm">
<error statusCode="403" subStatusCode="4" path="C:\Inetpub\wwwroot\Indexhome_.htm" responseMode="File" />
</httpErrors>
</system.webServer>
</configuration>
and the web.config which placed in root folder of blog directory where all wordpress file is below
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress: https://www.buyanddelight.com/blog" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I found many answers, but all are incomplete because some of them without cakephp some of them without wordpress and someof them without IIS server rest was not working so please help me out from this.
you can also refer below link to clarify my question as it can achieved by .htaccess but I am not able to find answer for IIS server web.config
finally i found the answer which work for me below is the code which work for me on iis server. create a web.config file as well under blog folder and put the below code
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<clear />
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
<outboundRules>
<clear />
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Good question and welcome to SO! In this scenario I would move Wordpress away from your CakePHP library. Your CakePHP environment would become extreme vulnerable. Wordpress has some security flaws that will affect your CakePHP environment aswell when you keep it as a subfolder. File inclusion, SQL injection, cross-site scripting and malware often comes together with dirty plugins and themes.

web.config 301 redirects, windows hosting

I'm struggling to get the web.config file working for redirects - I'm doing this for the first time. I've been trying plenty of different codes which I found on this site and elsewhere.
We have HTTPS site and I need to redirect HTTP url-s to HTTPS. The website is written in HTML and we have Windows hosting.
I set up a web.config file and added the code below.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Am I missing something here?
Or does it need some time to take effect?
Many thanks in advance!
Kadri
From Scott Hanselman's blog a few years ago, you should try this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS7 URL Rewrite for short urls

I've been working on a small link length supressor site and can't seem to figure it out on IIS7. I'm used to working on isapi rewrite and mod_rewrite.
The following scenario is active:
Lets say I have test.com, thats the main domain. The domain should process all files normally. But when the /.* isn't a directory nor a file, it should send it to redirect.asp?text=(.*).
This is what my web.config looks like
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="YOURLS 1" stopProcessing="true">
<match url="^([0-9A-Za-z-]+)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="redirect.asp?test={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Can't see much wrong with your rule, except maybe that you use test (with an 's') as the query string parameter in your web.config but in your text you say that it should be text. A typo or maybe that's the reason it's not working?
<action type="Rewrite" url="redirect.asp?text={R:1}" appendQueryString="false" />
It seemed to have to do with a wrong version of the URL rewriter. I installed the latest 2.0 and it was fixed!

URL rewrite - web.config error

I am getting the following error when i run my .aspx page.
Error Code0x8007000d
The configuration section 'rewrite' cannot be read because it is missing a section declaration
I have a simple v.aspx page which has the following code:
Response.Write(Request("q"))
My hosting server as IIS 7 installed with URL rewrite feature enabled (that's what they claim)
My web.config file has the following lines under :
Note: The node has blue squiggly lines under it
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" 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="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
I have searched stackoverflow but did not find a solution.
May be someone found a solution.
TIA
Make sure your <rewrite> is enclosed in the <system.webServer></system.webServer> section.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" 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="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Install the URL Rewrite module http://www.iis.net/download/URLRewrite and that should be sorted. It fixed my problem
The rewrite section in system.webServer is supported in IIS7, but not IIS6. The error is likely caused by deploying this site to a server that's only running IIS6.

Resources