I moved my zend project from Apache to IIS 7 and set up URL Rewrite.
The home page shows just fine, but the css and javascript aren't loading.
Here is my rewrite scripts
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="public/index.php" />
</rule>
<rule name="Imported Rule 1-1" stopProcessing="true">
<match url="\.(js|ico|txt|gif|jpg|png|css)$" ignoreCase="false" negate="true" />
<action type="Rewrite" url="public/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Here are the original mod_rewrite rules
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
Any suggestions?
After combing through Zend2 documentation, I found this example. Works perfectly! I hope this helps someone else out.
<?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>
Related
hello guys i have a wordpress multisite that hosted in iis how can you convert htaccess code to web.cofig?
Example:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
how to add that in my web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule 1" stopProcessing="true">
<match url="^index\.php$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="WordPress Rule 2" stopProcessing="true">
<match url="^wp-admin$" ignoreCase="false" />
<action type="Redirect" url="wp-admin/" redirectType="Permanent" />
</rule>
<rule name="WordPress Rule 3" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="WordPress Rule 4" stopProcessing="true">
<match url="^(wp-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="WordPress Rule 5" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
<action type="Rewrite" url="{R:2}" />
</rule>
<rule name="WordPress Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
can you help me with this one guys please.. T_T
For this pc of code
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
i am using
<rule name="rule 1A" stopProcessing="true">
<match url="." />
<action type="Rewrite" url="/index.php" />
</rule>
but not work... why ?
This config is solved my problem
<?xml version="1.0"?>
<rewrite>
<rules>
<rule name="DeduplicateSlashes" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
</rule>
<rule name="CleanRouting" 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="?id={R:0}&{QUERY_STRING}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<!-- Double escaping is needed for URLs with '+', e.g. for the account page for a username with a space. -->
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</configuration>
I am currently in the process of moving from parallels plesk for centos to parallels plesk for windows. The only snag i've hit is I realized .htaccess won't work anymore.
Here was my .htaccess:
options -indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^(verify)/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$3&hash=$4 [QSA,L]
RewriteRule ^(post)/([a-zA-Z0-9_-]+)$ news.php?post=$2 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^uploads/avatars/(.+)$ ../uploads/avatars/$1 [L,NC]
Redirect 301 /signup /register
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
errordocument 404 /404.php
errordocument 403 /404.php
errordocument 500 /404.php
allow from all
#deny from all
#allow from 98.115.168.25
deny from 162.144.91.203 #attempted brute force
deny from 74.208.100.64 #attempted brute force
deny from 185.57.82.25 #tried to ddos
Here is the web.config I generated with a website:
<rule name="rule 1F">
<match url="^(.*)$" />
<action type="Rewrite" url="/{R:1}.php" />
</rule>
<rule name="rule 2F" stopProcessing="true">
<match url="^(verify)/(.*)/([a-zA-Z0-9_-]+)$" />
<action type="Rewrite" url="/validate_account.php?usr={R:3}&hash={R:4}" appendQueryString="true" />
</rule>
<rule name="rule 3F" stopProcessing="true">
<match url="^(post)/([a-zA-Z0-9_-]+)$" ignoreCase="true" />
<action type="Rewrite" url="/news.php?post={R:2}" appendQueryString="true" />
</rule>
<rule name="rule 4F" stopProcessing="true">
<match url="^uploads/avatars/(.+)$" ignoreCase="true" />
<action type="Rewrite" url="/../uploads/avatars/{R:1}" />
</rule>
<rule name="rule 5F">
<match url="(.*)" />
<action type="Rewrite" url="/https://%{HTTP_HOST}%{REQUEST_URI}" />
</rule>
<rule name="rule 6F" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/http://%1%{REQUEST_URI}" />
</rule>
It gives me 500 internal server error whenever I try accessing the site, any help would be appreciated.
Try this and let me know
<rule name="rule 1X">
<match url="^(.*)$" />
<action type="Rewrite" url="/{R:1}.php" />
</rule>
<rule name="rule 2X" stopProcessing="true">
<match url="^(verify)/(.*)/([a-zA-Z0-9_-]+)$" />
<action type="Rewrite" url="/validate_account.php?usr={R:3}&hash={R:4}" appendQueryString="true" />
</rule>
<rule name="rule 3X" stopProcessing="true">
<match url="^(post)/([a-zA-Z0-9_-]+)$" ignoreCase="true" />
<action type="Rewrite" url="/news.php?post={R:2}" appendQueryString="true" />
</rule>
<rule name="rule 4X" stopProcessing="true">
<match url="^uploads/avatars/(.+)$" ignoreCase="true" />
<action type="Rewrite" url="/../uploads/avatars/{R:1}" />
</rule>
<rule name="rule 5X">
<match url="(.*)" />
<action type="Rewrite" url="/https://%{HTTP_HOST}%{REQUEST_URI}" />
</rule>
<rule name="rule 6X" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/http://%1%{REQUEST_URI}" />
</rule>
After installing the free version of ISAPI Rewrite I was able to use .htaccess with IIS 7.
I have a godaddy (windows) hosting account and I want to redirect:
www.example.com/folder/some to www.example.com/folder/some.html
I tried adding this Web.config file, but cannot find what rule to add for redirecting the html
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Add www" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" negate="true" pattern="^www\.(.+)$" />
<add input="{HTTP_HOST}" negate="true" pattern="^[^.]*dav.*" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Try using the following code in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I have a website on which i have installed Gallery3. The url is
http://techblog.lalsofttech.com/gallery/
But when i open the "test album", in the url there is index.php
http://techblog.lalsofttech.com/gallery/index.php/test
Now what i want is to remove the index.php from the url and want the url to look like this
http://techblog.lalsofttech.com/gallery/test
Since my shared server space is a windows platform with IIS 7, i cant use the .htaccess file.
Since my server got Microsoft URL Rewrite module installed i need to write the rewrite rule in web.config file.
This is the code for hiding the index.php in the .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /gallery
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>
I tried to convert this by installing the Microsoft URL Rewrite module in my localhost.
Except the "RewriteBase /gallery" all the other codes get converted ."RewriteBase /gallery is not converted because it is not supported by IIS" is the error message i got.
And this is the converted code.
<rewrite>
<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?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^index.php/(.*)" ignoreCase="false" />
<action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
But it seems this code is not working as the index.php is still there. The ISS URL Rewrite Module is working since another rule "Enforce canonical hostname" which i added in the web.config is working properly.
This is my complete web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="Enforce canonical hostname" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.moviega\.com$" />
</conditions>
<action type="Redirect" url="http://www.moviega.com/{R:1}" redirectType="Permanent" />
</rule>
<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?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^index.php/(.*)" ignoreCase="false" />
<action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
So where is the problem??. What should be done to remove the index.php from the url??
Please help me sort this out.
This may have to do with where1 you place this Web.config file. As long as it is in the http://www.MovieGa.com/gallery/ subdirectory, I think it should work...!
EDIT:
In response to your second question, here is probably why that error is happening:
It has to do with this part:
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" />
</rule>
With .htaccess, I think this works fine. But with Web.config, it gives you that error because2 it's trying to find capture groups in regex while there are none in this particular <match url="^$"> section. If you remove that ?kohana_uri={R:1} part from the url="", does it work?
Reference:
1 http://forums.iis.net/t/1162232.aspx (Anil Ruia's comment)
2 http://forums.iis.net/t/1150904.aspx (ruslany's second comment)
Ok i will make things clear here,for those who are installing gallery 3 in Windows Server with IIS7
and are trying to get rid of the index.php file from the url.
1st : Keep your web.config file with the rewrite rules in the directory where you are installing gallery and not the root of your website
2nd : The rewrite rules of the web.config file that you are placing inside the gallery folder should be like this
<?xml version="1.0" ?>
<configuration>
<system.webServer>
<rewrite>
<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?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^()$" ignoreCase="false" />
<action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^index.php/(.*)" ignoreCase="false" />
<action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Hope this will be useful for others who are facing the same problems like the one i encountered..