I have no experience working with windows web servers so i'm a bit lost. I'd like to setup a folder that routes all urls to index.php. I have attempted a few different configurations without any of them working.
How I would do it in .htaccess:
RewriteEngine on
RewriteBase /Software
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /folder/index.php?/$1 [NC,QSA,L]
My attempts with web.config:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect To Index" 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="/folder/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Place the below rules in webconfig file under the Software directory. If the webconfig file doesn't exists, create it. the rules in it can be recognized by IIS.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{R:1}" pattern="^(index\.php|images|robots\.txt)" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/folder/index.php?/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
IIS rewrite rules are designed with a different philosophy. It doesn’t support the RewriteBase command. We just place the webconfig file in the corresponding folder. The rest URL rules will work in the specific directory.
In addition, the rest URL rules could be automatically converted into IIS Rewrite Rules by using the below IIS features.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/importing-apache-modrewrite-rules
About how to convert the RewriteBase command.
https://forums.iis.net/t/1162790.aspx
Feel free to let me know if there is anything I can help with.
Related
There's a way to point all my subdomains to the same name folder, using Windows Server | IIS - Rewrite Rule or Proxy?
Example:
subdomain1.domain.com ----> C:\customers\development\subdomain1
subdomain2.domain.com ----> C:\customers\development\subdomain2
subdomain3.domain.com ----> C:\customers\development\subdomain3
Is it possible do automatically?
I've tryied these web.config rules
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks in advance!
URL rewrite is mainly used to rewrite URL not physical path. So you have to create a web app with root folder C:\customers\development and bind all subdomains to this IIS site. Then modify your rule to
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/{REQUEST_URI}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Please modify ^(?!www\.)(.*)\example\.com$ to ^(?!www\.)(.*)\.example\.com$.
Finally, you should be point subdomain to subfolder
Besides, if the application in folder domain1/domain2 and domain3 are three independent projects then you need to use sub-application instead of a folder.
I would like to take the following URL
http://MYSERVER/API_Tasks/V1/controller/task.php?taskid=2
and rewrite it to:
http://MYSERVER/API_Tasks/V1/tasks/2
I have the following rule created but it does not seem to work
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^tasks/([0-9]+)$" 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="controller/task.php?taskid={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
original Apache .htaccess rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tasks/([0-9]+)$ controller/task.php?taskid=$1 [L]
The issue was actually caused by the rule in IIS being placed on the API_Tasks directory and not the API_Tasks/V1 directory. Adding the URL rule to the V1 fixed the issue.
so I uploaded my website in GoDaddy and I used a Windows Hosting (Plesk). My only problem is that since it isn't running Apache as far as I know, it won't read my .htaccess file, which has all of my mod_rewrite code to remove the index.php in the URL. So my question is how do I implement a mod_rewrite in Plesk?
You can rewrite .htaccess file to IIS's web.config and place it inside /httpdocs folder.
You can do it by guides like this or this online converter or if you have Windows Server you can convert .htaccess by this guide (or you can share your .htaccess and i'll try to convert it for you)
I've found this snippet maybe it can help you:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Index">
<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>
</rewrite>
</system.webServer>
</configuration>
I have searched all over this site and the web and still I cannot get this right. I have many URLs like this: http://archives.cancunandrivieramaya.com/archives/cancun.cgi/md/read/id/XXXX that I want to redirect to the home page http://www.cancunandrivieramaya.com/. The subdomain no longer exists. How do I write the mod-rewrite to redirect the subdomain with wildcard characters at the end to the homepage? This is one of the 100's that don't work :(
RewriteCond %{HTTP_HOST} !^www\.cancunandrivieramaya\.com [NC]
RewriteCond %{HTTP_HOST} ^archives\.cancunandrivieramaya\.com([a-z0-9]+)\
RewriteRule (.*) http://www.cancunandrivieramaya.com/[L,QSA]
Any help would be much appreciated.
I got it! Thanks to this article by Altaf Khatri http://www.altafkhatri.com/Technical/Configure/How-to-publish-or-host-subdomain-on-winhostcom/Solution-resolution I was able to follow his step-by-step instructions for setting up the subdomain on WinHost, then I added this rule to the web.config file:
<rule name="archive redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.archives\.cancunandrivieramaya\.com$" />
</conditions>
<action type="Redirect" url="http://www.cancunandrivieramaya.com/" />
</rule>
<rule name="archives 2" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?archives\.cancunandrivieramaya\.com$" />
<add input="{PATH_INFO}" pattern="^/archives/($|/)" negate="true" />
</conditions>
<action type="Redirect" url="http://www.cancunandrivieramaya.com/" />
</rule>
Works perfectly!
I want to all www domain to naked via IIS Rewrite engine. There are many domains pointing to same application.
Here is my rule :
^(www.)(.*)$
Action Type : Redirect
Redirect URL : {R:2}
Redirect Type : Permanent
When i test pattern for www.xxx.com
R:0 => www.stackoverflow.com R:1=> www. R:2 => www.stackoverflow.com
and that is fine.
What is wrong? And also should I include "http://" ?
Something like ^(www\.)(.+)$ should work when matching the http_host, but it might be better to specify the domain. From what I know of IIS (not much) and what it says on the net, something like:
<rewrite>
<rules>
<rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
Oh, you said for any domain. If you want to make sure it ends in .com it should be something like
^(www\.)(.+)(\.com)$ against HTTP_HOST
.. oh, if you do that you need to back reference, so try something like this:
<rewrite>
<rules>
<rule name="Redirect www.domain.com to domain.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The c:1 is a back reference