**
I change my rewrite rule to change my website link from www.mydomain.com/index.php?do=/blog to www.mydomain.com/blog after this when i tried the below code, it won't let me change any page, like if i want to go for www.mydomain.com/blog, i just got stucked at www.mydomain.com, means redirect to my same root page,
what changes should i made for this please help. i am a newbei
my code is**
`<rule name="Redirect index.php" stopProcessing="true">
<match url="index\.php/(.*)" />
<action type="Redirect" url="{R:1}" appendQueryString="false" />
</rule>
<rule name="Rewrite index.php">
<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>`
Based on this forum post about .htaccess rewrites, you need to rewrite to:
index.php?do=/{R:1}
You are missing the ?do= part in the middle.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)_([0-9]*?)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="file/pic/photo/{R:1}/{R:2}/{R:3}_{R:5}.{R:6}" />
</rule>
<rule name="Imported Rule 2">
<match url="^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="file/pic/photo/{R:1}/{R:2}/{R:3}.{R:5}" />
</rule>
<rule name="Imported Rule 3">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://www.%" />
</rule>
<rule name="Imported Rule 4" 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="Redirect" redirectType="Permanent" url="{URL}/" />
</rule>
<rule name="Imported Rule 5">
<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?do=/{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 6">
<match url="^file/pic/photo/(.*)\.(.*)$" ignoreCase="false" />
<action type="Rewrite" url="static/image.php?file={R:1}&ext={R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Related
How can we combine these two rules for IIS?
"mod_rewrite" - redirects all requests to the PHP script to index.php
The second is a classic redirect from http to https
But the trouble is that either one or the other works, the two rules do not work together, tell me how to combine them?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Silex Front Controller" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
<rule name="http-to-https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You could implement both of the rule at same time. you just need to change the order of the rule. place the https redirect rule at first:
<rule name="http-to-https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
<rule name="Silex Front Controller" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
I would like to use part of the filename as a folder name, my redirect is working but the rewrite does not work, this is my web.config (also has a rule to remove the file extension):
Original: https://www.ipressnet.com.br/v6/client_tracking.aspx?id=x
Rewrite: https://www.ipressnet.com.br/v6/client/tracking?id=x
THIS WORKS:
<rule name="RemoveASPx" enabled="true" stopProcessing="false">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="AddASPx" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
THIS DOES NOT WORK:
<rule name="RemoveClient" enabled="true" stopProcessing="false">
<match url="^v6/?$|^client_(.*)$" />
<action type="Redirect" url="client/{R:1}" />
</rule>
<rule name="AddClient" enabled="true">
<match url="^v6/client/(.*)$" negate="false" />
<action type="Rewrite" url="v6/client_{R:1}.aspx" />
</rule>
I appreciate any help, thank you!
You can write RemoveASPx and RemoveClient in the same rule.
The following rule maybe achieve your requirement.
<rule name="rewrite rule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/v6(.*)client_(.*)\.aspx$" />
</conditions>
<action type="Redirect" url="v6{C:1}client/{C:2}" redirectType="Temporary" />
</rule>
<rule name="(.*)" enabled="false">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/v6/client/(.*)" />
</conditions>
<action type="Rewrite" url="v6/client_{C:1}.aspx" />
</rule>
<rule name="r1" stopProcessing="true">
<match url="v6/(client)?(_)?(.*).aspx" ignoreCase="false" />
<action type="Rewrite" url="v6/{R:1}/{R:3}" />
</rule>
I am having a hard time getting the below redirect rule to work...
<rules>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
The issue is as follows...
If i enter http://mywebsite.com it redirects to https://mywebsite.com no problem.
however, if i enter http://mywebsite.com/faq it is redirecting to https://mywebsite.com instead of https://mywebsite.com/faq and i cannot figure out why? It appears to be ignoring the '{R:1}' back reference that would come from my match which should be 'faq'
I've been battling with this for a while, any ideas on what is going on here would be great.
Some additional information is that i am hosting an angular 4.0 site that this rule is applied to...
Reversing the rules worked.
<rewrite>
<rules>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
I can redirect and make a single Friendly URL:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Product/Tour\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="Product/Tour" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^Product/Tour$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Product/Tour.aspx" />
</rule>
But, for example, if I have:
http://www.domain.com/Product/Features.aspx
http://www.domain.com/Product/Download.aspx
http://www.domain.com/Product/FAQ.aspx
etc.
Can I write one rule to make friendly URL for all of these links in order to receive?
http://www.domain.com/Product/Features
http://www.domain.com/Product/Download
http://www.domain.com/Product/FAQ
It's easy when there is a couple of links, but with a lot of rules it's hard to maintain.
You can use the regex pattern and the back reference to do this:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Product/([A-z0-9]+)\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="Product/{R:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^Product/([A-z0-9]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Product/{R:1}.aspx" />
</rule>
If you have a lot of urls to rewrite, you should read the documentation about the Rewrite Maps as well.
Ok, this is driving me nuts... I'm trying to rewrite my urls like this:
Now:
http://www.somedomain.com/Somepage.aspx
http://www.somedomain.com/AnotherPage.aspx
Desired:
http://www.somedomain.com/somepage/
http://www.somedomain.com/anotherpage/
Can anyone help me out with this? The terms in the User Interface are damn confusing.
Thanks.
I found the answer:
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="^([^\.]+)\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
</conditions>
<action type="Redirect" url="{ToLower:{R:1}}/" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="Rewrite" 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="{R:1}.aspx" />
</rule>
</rules>
</rewrite>