Programmer's Reference Guide

Module Structure

Rewrite Configuration Guide

URL rewriting is a common function of HTTP servers. However, the rules and configuration differ widely between them. Below are some common approaches across a variety of popular web servers available at the time of writing.

Apache HTTP Server

All examples that follow use mod_rewrite, an official module that comes bundled with Apache. To use it, mod_rewrite must either be included at compile time or enabled as a Dynamic Shared Object (DSO). Please consult the » Apache documentation for your version for more information.

Rewriting inside a VirtualHost

Here is a very basic virtual host definition. These rules direct all requests to index.php, except when a matching file is found under the document_root.

  1. <VirtualHost my.domain.com:80>
  2.     ServerName   my.domain.com
  3.     DocumentRoot /path/to/server/root/my.domain.com/public
  4.  
  5.     RewriteEngine off
  6.  
  7.     <Location />
  8.         RewriteEngine On
  9.         RewriteCond %{REQUEST_FILENAME} -s [OR]
  10.         RewriteCond %{REQUEST_FILENAME} -l [OR]
  11.         RewriteCond %{REQUEST_FILENAME} -d
  12.         RewriteRule ^.*$ - [NC,L]
  13.         RewriteRule ^.*$ /index.php [NC,L]
  14.     </Location>
  15. </VirtualHost>

Note the slash ("/") prefixing index.php; the rules for .htaccess differ in this regard.

Rewriting within a .htaccess file

Below is a sample .htaccess file that utilizes mod_rewrite. It is similar to the virtual host configuration, except that it specifies only the rewrite rules, and the leading slash is omitted from index.php.

  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} -s [OR]
  3. RewriteCond %{REQUEST_FILENAME} -l [OR]
  4. RewriteCond %{REQUEST_FILENAME} -d
  5. RewriteRule ^.*$ - [NC,L]
  6. RewriteRule ^.*$ index.php [NC,L]

There are many ways to configure mod_rewrite; if you would like more information, see Jayson Minard's » Blueprint for PHP Applications: Bootstrapping.

Microsoft Internet Information Server

As of version 7.0, IIS now ships with a standard rewrite engine. You may use the following configuration to create the appropriate rewrite rules.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3.     <system.webServer>
  4.         <rewrite>
  5.             <rules>
  6.                 <rule name="Imported Rule 1" stopProcessing="true">
  7.                     <match url="^.*$" />
  8.                     <conditions logicalGrouping="MatchAny">
  9.                         <add input="{REQUEST_FILENAME}"
  10.                              matchType="IsFile" pattern=""
  11.                              ignoreCase="false" />
  12.                         <add input="{REQUEST_FILENAME}"
  13.                              matchType="IsDirectory"
  14.                              pattern=""
  15.                              ignoreCase="false" />
  16.                     </conditions>
  17.                     <action type="None" />
  18.                 </rule>
  19.                 <rule name="Imported Rule 2" stopProcessing="true">
  20.                     <match url="^.*$" />
  21.                     <action type="Rewrite" url="index.php" />
  22.                 </rule>
  23.             </rules>
  24.         </rewrite>
  25.     </system.webServer>
  26. </configuration>

Module Structure

Comments

It don't seems to be enough to make site work in IIS7.
I had to add a new rule to treat de files (js|ico|gif|jpg|png|css|swf) here it is:

<rule name="CSS Rule " stopProcessing="true">
<match url="^\.(js|ico|gif|jpg|png|css|swf)$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern="\.(js|ico|gif|jpg|png|css|swf)$"
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>

For me this resolved the problem of supporting files of my application.
I hope you enjoy.

My IIS 7 have no URL Rewrite native module. And now what!!

Now You have two options:
Download Helicon URL Rewrite Software (http://www.helicontech.com/isapi_rewrite/)
or
Download the x86 version of the URL Rewrite native module (http://go.microsoft.com/?linkid=9722533)

I tried both and, for me microsoft works better and rules are easy to understand.
I hope this can help someone like me to save my lost 3 days searching for a solution!!!
I work in:
Zend framework 1.10
PHP 5.3
MySQL:5.5
Server: IIS 5.1(WinXP)

The problem in rewriting rule
on apache with htaccess no problem

but the problem in IIS
I try using Isapirewrite4 but seems not work
always is giving me this message:
The page cannot be diplayed

Is there a solution to this problem؟

any help please..
downward a few times to try and do critiques hell's kitchen fox come together each person identical . realize that <a href=http://www.kitchendesignslayouts.com/finding-a-professional-professional-vs-performing-your-entire-own-dwelling-maintenance-along-with-restorations/>kitchen equipment kelowna</a> young child fluctuate pretended pieces <a href=http://www.kitchendesignslayouts.com/tips-to-get-a-great-deal-more-than-a-snow-package-deal/>kitchen package deals</a> you should do in a deplete dealing in .

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual