First thankyou anyone , Engilsh is not my native language
But this problem is very difficult for me
I need
http://xxxx.show.bis.tw/event_register/index.php?id=image01
to
http://xxxx.show.bis.tw/event_register/image01
and if the users enter http://xxxx.show.bis.tw/event_register/image01 on address bar
the website is can work
I think the rules is
users can input those
http://xxxx.show.bis.tw/event_register/image01
http://xxxx.show.bis.tw/event_register/index.php?id=image01
1.
http://xxxx.show.bis.tw/event_register/index.php?id=image01
Redirect like this http://xxxx.show.bis.tw/event_register/image01 and go to rule2
Rewrite <action type="Rewrite" url="index.php?id={C:1}" />
2.
http://xxxx.show.bis.tw/event_register/image01
just only Rewrite <action type="Rewrite" url="index.php?id={C:1}" />
my code is
if file and directory do Redirect or Rewrite website will broken (css/js/image)
I try to rule>1 and rule>2 write in one rule but it not work
I don't know how to fix it
<rewrite>
<rules>
// 1
<rule name="025" stopProcessing="true">
<match url=".*" />
<conditions> // file and directory not Redirect|Rewrite
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="{C:0}" appendQueryString="false" />
</rule>
// 2
<rule name="026">
<match url="index\.php(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=(.*)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
// 3
<rule name="027" enabled="true" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="/index.php?id=" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?id={R:1}" />
</rule>
</rules>
</rewrite>
thankyou anyone very thank
I almost tow days can't not sleep just fix this
Have you tried rewritemaps instead of rules in your web.config file?
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="rewrites">
<add key="/event_register/image01" value="/event_register/index.php?id=image01" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
Related
The setup is the following :
i have 2 websites : one public and one private for our internal ERP. By using the same domaine name :
lesterrassesdadrien.fr.
When using the ARR it allow me to have the following : when someone ask for "lesterrassesdadrien.fr" the router will redirect the demand to the public website which is a wordpress, if the demand ask for "lesterrassesdadrien.fr/erp" it will redirect towards our erp website which is in PHP. here is the code inside the file applicationHost.config for the server in IIS:
<rewrite>
<globalRules>
<clear />
<rule name="lesterrassesdadrien_erp" patternSyntax="Wildcard" stopProcessing="true">
<match url="erp/*" />
<conditions>
<add input="{HTTP_HOST}" pattern="lesterrassesdadrien.fr" />
</conditions>
<action type="Rewrite" url="http://lesterrassesdadrien_erp/{R:1}" />
</rule>
<rule name="lesterrassesdadrien_public" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="lesterrassesdadrien.fr" />
<add input="{SERVER_PORT}" pattern="5000" negate="true" />
<add input="{SERVER_PORT}" pattern="5001" negate="true" />
</conditions>
<action type="Rewrite" url="http://lesterrassesdadrien_public/{R:1}" />
</rule>
</globalRules>
</rewrite>
</system.webServer>
<webFarms>
<webFarm name="lesterrassesdadrien_erp" enabled="true">
<server address="127.0.0.1" enabled="true">
<applicationRequestRouting httpPort="5000" />
</server>
</webFarm>
<webFarm name="lesterrassesdadrien_public" enabled="true">
<server address="127.0.0.1" enabled="true">
<applicationRequestRouting httpPort="5001" />
</server>
</webFarm>
</webFarms>
My problem is that when we click on a link inside the ERP website for exemple :
lesterrassesdadrien.fr/admin/... it will fail and bring me back to the public wordpress website : how to keep or add the "erp/" in front of all link inside my erp website?
My explanation are a bit confusing i believe.
Thanks in advance.
I tried to add this to the rules but with no aval :
<rule name="lesterrassesdadrien_admin" patternSyntax="Wildcard" stopProcessing="true">
<match url="admin/*" />
<conditions>
<add input="{HTTP_HOST}" pattern="lesterrassesdadrien.fr" />
</conditions>
<action type="Rewrite" url="http://lesterrassesdadrien_erp/erp/{R:1}" />
</rule>
I am trying to rewrite my url with a web.config file.
Actual URL: sudomain.mydomain.com/legal.html
Wished URL: legal.mydomain.com
I have already hide the html extension.
<rule name="Hidehtml" enabled="true">
<match ignoreCase="true" url="Legal" />
<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="Legal.html"/>
</rule>
I saw this kind of rewrite is possible with subfolder, but I wonder if it is possible with a file.
I am trying this one but it give me a DNS error.
<rule name="testrule" stopProcessing="true">
<match url="legal(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://legal.mydomain.com" />
</rule>
I wonder if I am not missing something, maybe a redirect is needed too?
Thanks for your help !
To achieve this,
I just registered two CNAME for my website.
FQDN:subdomain.mydomain.com
FQDN:legal.mydomain.com
Then I apply them to my IIS site.
Just make sure both of them can be accessed in web browser.
Then I apply following rewrite rules
<rules>
<rule name="testrule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/legal\.[a-zA-Z]+" />
<add input="{HTTP_HOST}" pattern="subdomain.candy.com" />
</conditions>
<action type="Redirect" url="http://legal.candy.com" />
</rule>
<rule name="rewrite rule">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="legal.candy.com" />
<add input="{URL}" pattern="^(/)?$" />
</conditions>
<action type="Rewrite" url="http://subdomain.candy.com/legal.html" />
</rule>
</rules>
When you access sudomain.mydomain.com/legal.html, the request will be redirected to legal.mydomain.com/ and legal.mydomain.com will rewrite back to /legal.html for response content.
Please keep in mind that legal.mydomain.com is always required to be registered in DNS even you just use it as a mask.
If your website are forwarding the public internet, please remember to purchase domain for legal.domain.com as well.
When playing with the Temphire app, I noticed that when I try to refresh a page by hitting F5, the application shows a blank page ! (ngViewport is not rendered)
Found the solution... it was an IIS issue, needed to rewrite urles in order to keep it working :
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<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>
I have a problem. On IIS I got a web-site with two ports 80 and 443(https). I want to redirect all the http requests from user to https. I also added Rewrite rule to https, but when I enter in browser http://localhost/site it gives me the same page. I need to redirect user to httpS://localhost/site.
Maybe this is because of my local configurations?
And I disable Require SSL on IIS.
The rule is:
<rewrite>
<rules>
<rule name="HTTPS Redirect">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
Thank you.
Below is the exact rule we use on a production IIS 7 site to redirect all request from HTTP to HTTPS
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect 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>
There are some minor differences between what you have posted and what we use. Also, since you are running on local host, you wouldn't be using the built-in web server with visual studio would you? I don't think it will process IIS rewrite rules.
I realize this may not be your issue, however I had a similar debacle that was cause by a different problem.
I had enabled Require SSL and that caused the site to continually return a 403. So to use this method it appears you must disable SSL Settings -> Require SSL.
Hope this helps someone.
Also, if you have more than one rule, order could matter. Be sure to add the redirect rule before other rules or redirect may not fire.
Here is an example that is using SPA that required the rule order.
<rules>
// Adding this as last rule will cause it to not redirect
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="static dist files" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{APPL_PHYSICAL_PATH}app\{R:1}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="index.html as document root" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="/app/" />
</rule>
<rule name="SPA Routes" stopProcessing="true">
<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="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/app/" />
</rule>
</rules>
It works for me in IIS 8.5
redirect
Three points:
Use single word OFF rather than ^OFF$
Use url="https://{HTTP_HOST}/{REQUEST_URI}"
Use redirectType=Permanent rather than Found although both are working but preferable Permanent type in this case
The webconfig code
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
you can add this to your pages. to force redirection.
if (!Request.IsSecureConnection)
{
Uri uri = new Uri(Request.Url, Request.RawUrl);
Response.Redirect(string.Format("https://{0}{1}{2}", uri.Host.StartsWith("www.x.com") ? uri.Host : "www.x.com", uri.AbsolutePath, uri.Query));
}
I just seen your tag of mvc
add this attribute to your actions. or controllers.
[RequireHttps]
I'm trying to rewrite all the urls for my website.
For example, if the user types in mysite.com/index.aspx
it'll change the url in the top to www.mysite.com/index.aspx
Any suggestions?
Try this one
<rewrite>
<rules>
<rule name="Enforce canonical hostname" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.mysite\.com$" />
</conditions>
<action type="Redirect" url="http://www.mysite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>