Htaccess and CakePHP 2 on windows IIS7 - .htaccess

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 /.

Related

Zend Framework 2 in IIS in subdirectory

My ZF2 project is in a subdirectory within my IIS 7.5 server, but the rewrite doesn't work.
The application only works through www.domain.com/directory/subdirectory/public/index.php/controller/action.
How can I configure rewrite in IIS
You need to configure the build rewrite engine in IIS. Put this file into web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern=""
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
More information:
Zend Framework 2 Installation
URL Rewrite

ZF2 site on IIS 7 subdomain routing not working

I have a shared Windows hosting account on Ez-DomainNameRegistration. I have setup a subdomain that routes to a subfolder and uploaded my Zend framework website to the folder. FYI: the website works on my local pc on IIS 7. The problem I have is that the layout of the site is correctly loaded, but the controller-action routing does not work. Instead of the view of the action I get the 404 error view. My guess is that it has something to do with the url routing.
In the route folder (the subfolder pointed to by the subdomain) I have the following web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 14" stopProcessing="true">
<match url="\.(js|gif|jpg|png|css|txt|svg)$" negate="true" ignoreCase="false" />
<action type="Rewrite" url="public/index.php{R:1}" />
</rule>
<rule name="Imported Rule 15" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
And in the public folder I have the following web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Is there something I can change to make the routing work in side a subdomain/subfolder on iis 7?

web.config URL rewrite not rewriting

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!

Redirect rules in windows host

I have a widows machine hosted by goddady and I need to create a rule to forward any request with a URL pointing to a non-existing file to be sent to the index.php.
Usually I would do that with the .htaccess but its different in windows hosts.
I found the answer.
I had to put a xml file named 'web.conf' in the root directory, it works in the same way .htaccess does.
I took the rules from ZendFramework Site
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern=""
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This rules will make the server check if the file exsists and if it doesn't then the request is forwarded to index.php

IIS Rewrite rule with QueryString in Rewrite

I'm having a problem with an IIS rewrite rule. We have many set up and working in our web.config file. I am trying to modify one of them. Apologies for the level of this question. I'm not experienced in this topic.
The current rule is:
<rule name="my-rule-test" stopProcessing="true">
<match url="^my-page.asp" />
<action type="Rewrite" url="/my-domain/my-actual-page.asp" />
</rule>
This rule works fine. I'm now trying to simply add a QueryString to the Rewrite page as follows:
<rule name="my-rule-test" stopProcessing="true">
<match url="^my-page.asp" />
<action type="Rewrite" url="/my-domain/my-actual-page.asp?aS=h" />
</rule>
This rule fails and trips the server over to the page we have set up in web.config here:
<system.web>
<customErrors defaultRedirect="c:\test.html" mode="On">
</customErrors>
</system.web>
Can somebody please let me know what I'm doing wrong?
Thanks,
J
Your formatting is not correct:Please refer to this.
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

Resources