The following is how Nginx is written:
location / {
try_files $uri $uri/ /index.php?$query_string;}
I want to get pseudo-static writing in iis environment,The same effect.
Thanks for helping me!
you could try the below URL rewrite rule to implement your requirement:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
make sure you have installed the iis URL rewrite module. if not you could download it from the below link:
https://www.iis.net/downloads/microsoft/url-rewrite
Related
How can we combine these two rules for IIS?
"mod_rewrite" - redirects all requests to the PHP script to index.php
The second is a classic redirect from http to https
But the trouble is that either one or the other works, the two rules do not work together, tell me how to combine them?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Silex Front Controller" enabled="true" 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>
<rule name="http-to-https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You could implement both of the rule at same time. you just need to change the order of the rule. place the https redirect rule at first:
<rule name="http-to-https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
<rule name="Silex Front Controller" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
I have the following rules, but when I access https://myserver/myapp/sparoute/1 I get a 403 instead of the index.html
I got this config at root of myapp:
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy to API" stopProcessing="true">
<match url="api/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="https://internalserver/myapp/{R:0}" />
</rule>
<rule name="Reverse Proxy to Signalr" stopProcessing="true">
<match url="messagehub(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="https://internalserver/myapp/{R:0}" />
</rule>
<rule name="Handle History Mode for SPA (myapp)" 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>
The first two rules are working, but instead of returning the default index.html when rewriting to / i get a 403. Any ideas?
The rewrite url is relative to website. so the last action should be
<action type="Rewrite" url="/myapp" />
I've been having a problem recently with one of my rewrite rules in web.config. It's giving me a 500 error, yet it used to work in the past. I have, however, recently had to change it over from .htaccess to web.config, so I feel that may be part of the problem, but it used to work even after changing it over so I don't know what the problem is?
The web.config is currently sat as just imported rules now (default after importing now) and the content is the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" enabled="false" stopProcessing="true">
<match url="^images/([a-zA-Z0-9_-]+\.)(jpg|png|gif)$" ignoreCase="false" />
<action type="Rewrite" url="images/old/{R:1}{R:2}" />
</rule>
<rule name="Imported Rule 2" enabled="false" stopProcessing="true">
<match url="^images/thumbs/([a-zA-Z0-9_-]+\.)(jpg|png|gif)$" ignoreCase="false" />
<action type="Rewrite" url="images/old/{R:1}th.{R:2}" />
</rule>
<rule name="Imported Rule 3" enabled="false" stopProcessing="true">
<match url="^api$" ignoreCase="false" />
<action type="Rewrite" url="api.php" />
</rule>
<rule name="Imported Rule 4" enabled="false" stopProcessing="true">
<match url="^images/(\w*\.)(jpg|png|gif)$" ignoreCase="false" />
<action type="Rewrite" url="images/old/{R:1}{R:2}" />
</rule>
<rule name="Imported Rule 5" enabled="false" stopProcessing="true">
<match url="^images/thumbs/(\w*\.)(jpg|png|gif)$" ignoreCase="false" />
<action type="Rewrite" url="images/old/{R:1}th.{R:2}" />
</rule>
<rule name="Imported Rule 6" enabled="false" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="\.([a-z]{1,4})$" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I'm not the best at web.config, so if you know any reason as to why it may not be working after importing, can you help out? Thanks very much!
**
I change my rewrite rule to change my website link from www.mydomain.com/index.php?do=/blog to www.mydomain.com/blog after this when i tried the below code, it won't let me change any page, like if i want to go for www.mydomain.com/blog, i just got stucked at www.mydomain.com, means redirect to my same root page,
what changes should i made for this please help. i am a newbei
my code is**
`<rule name="Redirect index.php" stopProcessing="true">
<match url="index\.php/(.*)" />
<action type="Redirect" url="{R:1}" appendQueryString="false" />
</rule>
<rule name="Rewrite index.php">
<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/{R:1}" />
</rule>
</rules>`
Based on this forum post about .htaccess rewrites, you need to rewrite to:
index.php?do=/{R:1}
You are missing the ?do= part in the middle.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)_([0-9]*?)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="file/pic/photo/{R:1}/{R:2}/{R:3}_{R:5}.{R:6}" />
</rule>
<rule name="Imported Rule 2">
<match url="^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="file/pic/photo/{R:1}/{R:2}/{R:3}.{R:5}" />
</rule>
<rule name="Imported Rule 3">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://www.%" />
</rule>
<rule name="Imported Rule 4" 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="Redirect" redirectType="Permanent" url="{URL}/" />
</rule>
<rule name="Imported Rule 5">
<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?do=/{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 6">
<match url="^file/pic/photo/(.*)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="static/image.php?file={R:1}&ext={R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I was having problems trying to configure the mod rewrite over windows and II7:
CakePHP 2.2.2 not working on Windows IIS7 but finally i could import the htaccess in order to create the web.config file for IIS7.
The thing is:
Now that file has been created in cakephp folder and i can access to the main page BUT it has not been created inside app/ or app/webroot in which you can find 2 more .htaccess files.
Now, i can not access any other view than the main site, it shows a 404 page not found error and i am pretty sure that it is because it is not getting those .htaccess files on the web.config.
My cakephp web.config file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Although the CakePHP documentation tells you to add a different code (which makes the views work but no styles are loaded. And the home page don't work.)
http://book.cakephp.org/2.0/en/installation/advanced-installation.html#url-rewrites-on-iis7-windows-hosts
When trying to access a CSS file from the URL i get this message:
Missing Controller
Error: CssController could not be found.
Error: Create the class CssController below in file: app\Controller\CssController.php
<?php
class CssController extends AppController {
}
Any idea? Working with Cakephp over windows is driving me crazy...
I should mention that my response is an improvement on the solution posted here: http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/
A simpler and more flexible fix would be to get rid of /{Path_To_CakePHP_Directory}/ altogether, including the forward slash (/). By keeping the paths relative, your project folder becomes a lot more mobile. Here's what the web.config would look like:
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear/>
<rule name="Imported Rule 0" stopProcessing="true">
<match url="^(img|css|files|js)(.*)$"></match>
<action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false"></action>
</rule>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/{R:1}" />
</rule>
<rule name="Imported Rule 4" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Ok, finally i get it work using this web.config i found on this site:
http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/
I just changed the /{Path_To_CakePHP_Directory}/ for /.