I have this htaccess wich gets the folder added in the url and converts it into a variable. As follows:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?pagina=$1
I had to convert it to a web.config xml sctructured file, It worked like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^([a-zA-Z0-9_-]+)$" ignoreCase="false" />
<action type="Rewrite" url="/index.php?page={R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 2">
<match url="^([a-zA-Z0-9_-]+)/$" ignoreCase="false" />
<action type="Rewrite" url="/index.php?page={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Now I need to make it work only when this last folder is not an specific folder, I tried this after a research but no success:
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="!^/diretorio/" ignoreCase="true" />
</conditions>
I found out the correct code is:
<conditions>
<add input="{REQUEST_URI}" pattern="^/admin/" ignoreCase="false" negate="true" />
</conditions>
Related
I am using an shortname ( DNS entry) to map my angular 5 app URL.
Application is hosted in IIS as shown in the below image,
I have mapped the path to application to a short-name called "arcm".
So the moment, I type this short-name in browser address bar, I see my default route.
But the problem is,
if I refresh it on any route, I see 404 error.
Following is my web.config file and rewrite rule,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="AngularJS" stopProcessing="true">
<match url="arcm/" />
<action type="Rewrite" url="http://arcm/" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
the following changes resolve my issue,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Http Redirection" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP}" pattern="off" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
<rule name="AngularJS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" negate="true" pattern="\.axd$" />
<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>
I'm using iis-7.5 and web.config file.
I want to redirect "somepage.asp?id=63" to "somepage/10.html".
My web.config is like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect 2" stopProcessing="true">
<match url="somepage.asp?id=63" />
<action type="Redirect" url="somepage/10.html" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
it didn't work, when I change <match url="somepage.asp?id=63" /> to <match url="somepage.asp" />, (delete ?id=63) , it worked, why? how can i do?
As far as I know, the url rewrite match url pattern doesn't match query string.
If you want to redirect the url according to the query string, I suggest you could try to use condition.
More details, you could refer to below url rewrite rule:
<rule name="Redirect according to query string" stopProcessing="true">
<match url="somepage.asp" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=63" />
</conditions>
<action type="Redirect" url="somepage/10.html" appendQueryString="false" />
</rule>
I have a working rule that removes www. for all urls coming in. I have a webserivce that the redirect will change from a POST to a GET. I need to exclude the URL https://www.foo.net/WebServices/service.asmx from this rule.
I have looked at other solutions on SO with no success.
<rewrite>
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(foo\.net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>
</rules>
</rewrite>
You can do that easily by adding a condition to "not match" (aka adding "negate='true'" ), something like this should work:
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.foo\.net$" />
<add input="{URL}" pattern="^/WebServices/service\.asmx$" negate="true" />
</conditions>
<action type="Redirect" url="https://foo.net/{R:1}" />
</rule>
</rules>
This is how i currently want to redirect my site to
when i try navigating to
http://sub1.sitename.com it should redirect to sitename.com/newprojects/sub1
and the same for sub2
i tried using it like this but it ends up loading www.sitename.com
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="^sub1\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub1/" redirectType="Permanent" />
</rule>
<rule name="Redirect1" stopProcessing="true">
<match url="^sub2\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub2/" redirectType="Permanent" /> </rule>
</rules>
</rewrite>
You could try matching all the URL's and then filtering based on what you want to redirect.
<rewrite>
<rules>
<rule name="sub1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1\.site\.com(/)?$"/>
<add input="{PATH_INFO}" pattern="^/newprojects/sub1/" negate="true" />
</conditions>
<action type="Rewrite" url="\newprojects\sub1\{R:0}" />
</rule>
</rules>
</rewrite>
this worked for me.
How to remove index.php in codeigniter on Windows Azure and IIS?
Can I rewrite the URL for the index.php of Codeigniter without a particular module?
You can add rewrite rules in your web.config file. Add the following to the system.webServer section:
<rewrite>
<rules>
<rule name="Rule" 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" />
<add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Create a file name web.config in wwwroot
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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>
</rules>
</rewrite>
</system.webServer>
</configuration>
You can also implement other rewrite rules like
<rule name="a rule">
<match url="^xxx/(.*)/(.*)-(.*)\.xxx" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="controller/method/{R:3}" />
</rule>
with one condition, is to change $config['url_protocal']='PATH_INFO'; in config/config.php this will tell URL rewrite module to use re-writed URI instead of original URL, otherwise you will have 404 page not found problem.