Quantcast
Channel: URL Rewrite Module
Viewing all 2482 articles
Browse latest View live

removing .aspx extentions from url's

$
0
0

 hi guys,

I must say how glad I'm am that there is finally a built-in url rewriter, I've already transformed a horrible query string into something that is much easier on the eye.  Now I wish wish to extend it further to remove .aspx from all pages.  But I am having real trouble with it, I am sure many have done this before.  How did you do it?


 


IIS 7.5, URL Rewrite 2.0, Kerberos - rewritten URL returning 401.1

$
0
0

Greetings,

I would appreciate any hints regarding the following issue:

The problem summary:

While using Negotiate:Kerberos in IIS 7.5, the authorization works correctly right until we setup URL rewriting (using the MS module "URL Rewrite 2.0") - any rewritten URL then returns "401.1 Unathorized" (requests not matching any rewrite rule keep working though).

The setup:

  • Windows Server 2008 R2 x64
  • IIS 7.5
  • URL Rewrite 2.0

  • Server is in a domain

  • SPN exists for HOST/hostname and HOST/hostname.domain (created by default)
  • Pool is using default ApplicationPoolIdentity (no custom account, not network service)
  • Kernel mode set to OFF
  • Authentication providers set to "Negotiate:Kerberos" only (no NTLM or annonymous)

  • URL Rewrite rule as as "^(.*)/$" => "index?x={R1}"

The result:

1) When accessing any URL not matching any URL rewrite pattern, Kerberos is working correctly, i.e. Kerberos ticket is issued (verified using klist), sent (verified using netmon and HTTP headers) and accepted (verified by URL being accessible and appropriate AUTH_USER property set to my domain account name) => no problem here.

2) When accessing any URL matching URL rewrite pattern, e.g. "hostname/foo" the result is:

HTTP Error 401.1 - Unauthorized
You do not have permission to view this directory or page using the credentials that you supplied.
Module  WindowsAuthenticationModule
Notification    AuthenticateRequest
Error Code  0x80070055
Requested URL   http://hostname/index?x=foo
Physical Path   D:\wwwroot\
Logon Method    Not yet determined
Logon User  Not yet determined

(if we try to access the rewritten URL directly, e.g. hostname/index?x=foo, Kerberos works again normally)

The attempts to solve it so far:

After googling, we have tried several options:

  • turning kernel mode ON: Kerberos stopped working completely, using either default pool identity or network service (I suppose we would need to setup additional HTTP SPN and/or use custom domain account with additional SPN for that account explicitly)
  • turning "useAppPoolCredentials" ON: no difference
  • enabling "Failing Request Tracing": surprisingly these failing 401.1 requests ARE NOT generating any output into the fail logs no matter what rule we try to setup (e.g. 400-999) - the folder is just empty (while other errors, like 404 or even handshake 401.x when accessing not-rewritten URLs are generating logs - very strange)

The conclusion:

So far we have reached a dead end - it may be some weird kind of "double hop" issue requiring using a custom domain account rather than default app pool identity, but as we're in fact accessing the same resources, it seems more like a URL Rewrite issue.

Any tips, hints, pointers? Anything would be highly appreciated.

Best regards, Marek

Trouble with simple re-write

Dynamically change url in asp.net like Facebook and twitter

$
0
0

How can I use URL rewriting to change dynamically URL in asp.net on the basis ofusername in database like Facebook and Twitter by . 

Please see image below:

Twitter

twitter

Facebook

facebook

Change Request Method On Rewrite with IIS

$
0
0

I'm trying to set up a reverse proxy using IIS so that any request from googlebot (or any bot) will be proxied into another domain and will turn into a POST request, this is my web.config file:

<?xml version="1.0" encoding="UTF-8"?><configuration><system.webServer><rewrite><allowedServerVariables><add name="X_REQUESTED_URL_PATH" /><add name="HTTP_CONTENT_LENGTH" /><add name="HTTP_X_BABLIC_ID"/><add name="HTTP_X_ORIGINAL_URI"/><add name="HTTP_ACCEPT_ENCODING" /><add name="HTTP_METHOD"/></allowedServerVariables><rules><rule name="IsBOT" stopProcessing="true"><match url="(.*)" /><serverVariables><set name="HTTP_CONTENT_LENGTH" value="0"/><set name="HTTP_METHOD" value="POST"/><set name="HTTP_X_BABLIC_ID" value="[XXX]"/><set name="HTTP_X_ORIGINAL_URI" value="http://{HTTP_HOST}{UrlEncode:{URL}}"/><set name="HTTP_ACCEPT_ENCODING" value=""/></serverVariables><conditions><add input="{HTTP_USER_AGENT}" pattern="bot|crawler|baiduspider|facebookexternalhit|Twitterbot|80legs|mediapartners-google|adsbot-google"/></conditions><action type="Rewrite" url="http://[MY DOMAIN]"/></rule></rules></rewrite></system.webServer></configuration>

I thought that if I overwrite HTTP_METHOD it will cause the request to be POST but that's not working, any other way to achieve my goal?

(for technical reasons I must use only the web.config for that, so please do not forward me to a GUI guide).

Redirect all .asp files to .php in a specific folder

$
0
0

Hi,

I am using IIS which comes with Windows 10. I'm trying to set up a Rewrite rule / Redirect which directs all pages with an asp extension to the equivalent php file, including the querystring, but only within a folder called site.

Trouble is that I can't work out how I'd do that.

e.g. I'd like to redirect:
http://localhost/site/this.asp

To:
http://localhost/site/this.php

And also 

e.g. I'd like to redirect:
http://localhost/site/this.asp?version=25

To:
http://localhost/site/this.php?version=25

Is that possible, using web.config > configuration > system.webServer > rewrite > rules > New Rule...

Any advice much appreciated.

Thanks

How to use URL rewrite to redirect to different domain

$
0
0

hi everyone,

I want to use url rewrite to redirect to  the different domain and hide the .aspx extension  name.

http://mynewsite.com/default.aspx -> http://mynewsite2.com/default

Will appreciate you help 

Thanks

Remove or rename authorization header to backend

$
0
0

- I have an IIS proxy, IIS 8.5 / ARR
- The IIS proxy has Windows Authentication enabled, together with URL Authorization
- The proxy connects to a backend webapplication which does not like to receive Authorization headers
  Problem: IIS forwards Authorization headers to the application, application throws error about invalid Authorization headers.

How can i prevent IIS from forwarding the Authorization header to the backend webapplication?
I allready tried renaming the header to BOGUSHEADER but it doesnt seem to work. 

Configuration:

(i added HTTP_AUTHORIZATION to the allowed server headers)

<rewrite><rules><rule name="backend" stopProcessing="true"><match url="(.*)" /><action type="Rewrite" url="http://backend/{R:1}" /><conditions><add input="{HTTP_HOST}" pattern="frontendurl" /></conditions></rule></rules><outboundRules><rule name="RenameAuthorizationHeader"><match serverVariable="HTTP_AUTHORIZATION" pattern="(.*)" /><action type="Rewrite" value="{HTTP_BOGUSHEADER}" /></rule></outboundRules></rewrite>


Reset invalid Range request header

$
0
0

We have a bunch of legacy client applications that are sending an invalid byte-range request as part of the header (range: bytes=100)

I need a simple rule that will ignore the invalid request and NOT return an error.

Thanks!

Import from .htaccess

$
0
0

I switched to IIS7.5 from Apache, and try to import the rewrite rule file from my .htaccess file using IIS Manager, but something not working .

Rule:

^(account)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$
URL:
account/manage/5

should match first image below, but in IIS the result is second image....

correctwrong

is this a bug ? if not, how to rewrite my rule ?

EDIT:

After 2 hours, finally i found a way to fix it, hope this may help others that face the same problem.

change rule from

^(account)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$

to

^(account)(?:/([^/]+)(?:/([^/]+)(?:/([^/]+))?)?)?/?$

should work fine with IIS, i think both rule should work fine with Apache and IIS.

URL rewrite with http header

$
0
0

Hi, I'm learning how to use URL rewrite recently.The reference said URL rewrite rule could pattern the request header. How could I do that.

Besides, if i want to redirect the rule from  http://www.mywebsite.com/market?id=3 ->www.mytagetwebsite.com/market?usrid=3

Any help will be appreciated.

Simple rewrite not working

$
0
0

I can't seem to get a simple rewrite to work.  I need to rewrite incoming vanity host names to a vroot on our canonical site.  I have CNAME records in place to get the requests to the canonical site: game.vanityname.com  CNAME  realname.network.com, game2.vanityname.com  CNAME  realname.network.com, game3.vanityname.com  CNAME  realname.network.com, game4.vanityname.com  CNAME  realname.network.com.

I thought I should be able to capture all *.vanityname.com except www.vanityname.com using regular expressions:

<rule name="Vanity-Rewrite" stopProcessing="true">
     <match url=".*" />
     <conditions>
         <add input="{HTTP_HOST}" pattern="^(?!www)(*)\.vanityname\.com$" />
     </conditions>
     <action type="Rewrite" url=http://realname.network.com/vanitylandingpage />
 </rule>

Then I tried using the actual vanity host names:

  <rule name="Vanity-Rewrite" stopProcessing="true">
      <match url="(?:game.vanityname.com|game2.vanityname.com|game3.vanityname.com|game4.vanityname.com)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Rewrite" url="http://realname.network.com/vanitylandingpage" appendQueryString="false" />
  </rule>

None of these are working.  It doesn't even look like IIS is attempting to intercept the request before it is handed off to our .NET application since I can see the 302 that our custom code issues for the vanity back to our root.

Any suggestions would be greatly appreciated.

URL Rewrite Add Custom Request Header

$
0
0

Hi:

I am trying to implement Single Sign On for a third party application. The third party application does not support it natively, but if it is fronted by another server that could feed it with the username, as a request header, then it can sign the user in automatically.

So my plan is to put IIS in front of the third party application. IIS will have Windows Integrated authentication enabled. When a user JOHN is authenticated by IIS, we need to pass the request to the third party application, with an additional request header called USER_NAME=JOHN. The third party application will read the header USER_NAME, and sign in as JOHN.

I am planning to use URL Rewrite to pass the request from IIS to the third party application. However, how can I pass the header? I know URL Rewrite module has a naming convention of replacing "_" to "-", so USER_NAME will become USER-NAME. Is there a way we can go around this naming convention? The third party application expects USER_NAME, not USER-NAME.

Thank you in advance for the help!

Trying to simplify a rewrite url

$
0
0

Hello

Using IIS 8.5

I have a the following rewrite rule setup which works fine.

<rule name="Case Study Materials"><match url="^case-studies/([0-9]+)/([_0-9a-z-]+)" /><action type="Rewrite" url="/case-studies/?material={R:1}&amp;title={R:2}" /></rule>

So for example /case-studies/material?123&title=coffee get rewritten to
/case-studies/123/coffee

Is there a way I can adjust the rule so that the rewritten url outputs /case-studies/coffee

Many Thanks

MSI Installation Failure

$
0
0

I am attempting to install "rewrite_amd64.msi" on a Windows 2012 R2 virtual machine that is running on AWS.

The installation fails with the error noted below.  The server has sufficient disk space (28.8 GB free on C Drive, 57.9 GB free on d drive).

Any ideas?

Action 6:21:43: GenerateScript. Generating script operations for action:
GenerateScript: CheckForSharedConfiguration
Error 1711. An error occurred while writing installation information to disk. Check to make sure enough disk space is available, and click Retry, or Cancel to end the install.
MSI (s) (80:48) [06:21:46:958]: Product: IIS URL Rewrite Module 2 -- Error 1711. An error occurred while writing installation information to disk. Check to make sure enough disk space is available, and click Retry, or Cancel to end the install.


URL Rewrite 2.0 and REMOTE_ADDR

$
0
0

I'm trying to find a solution to allow the client IP to be preserved using an X-Forwarded-For header from our hardware load balancer.  I would like to get this working with URL Rewrite 2.0 as this will be the most supportable option once v2.0 is released, but I'm having trouble getting the REMOTE_ADDR variable to be overwritten.

 I can successfully write the X-Forwarded-For value to a new HTTP_variable:

<set name="HTTP_Test" value="{HTTP_X_Forwarded_For}" replace="true" />

But when I try to set the REMOTE_ADDR variable, nothing happens:

<set name="REMOTE_ADDR" value="{HTTP_X_Forwarded_For}" replace="true" />

What am I missing here?

Wordpress site slow

$
0
0

I have a 2008 r2 server running iis 7.5.  It is setup as dual core with 8GB of ram as a VM.  I set this server up a while ago and its been running fine up until now.  When i setup the server i ran the microsoft web platform installer to setup wordpress and made the server a wordpress server for a user group on our network.  They have recently made me aware that the site is taking a long time to load.  The server isn't using that much ram but i have noticed that there is one instance of php-cgi.exe 32 using 50% of the cpu. Its not constant, I would say it stays at 50% for about 6-8 seconds then drops to low utilization for a few seconds then will go back to 50%.

It has been determined using failed request tracing that the RewriteModule is taking a long time:

I checked the URL rewrite settings and it doesn't appear I ever set any up so I dont get why this is slow.

Can anyone help?

Request: http://www.senate.iowa.gov:80/democrats/index.php
NOTIFY_MODULE_COMPLETION ModuleName:RewriteModuleNotification:BEGIN_REQUEST 
fIsPostNotificationEvent:falseCompletionBytes:0ErrorCode:The operation completed successfully.(0x0)26988 ms

Redirect to append incoming URL as a query string

$
0
0

Hi folks:

I'm new to IIS Rewrite rules and while I've searched this and other forums, cannot find find an answer and am hoping some experienced folks will help or point me in the right direction.

As an overview, I want any request to an internal website to be intercepted by IIS, and redirected to a page with information for the user to acknowledge. Once the user acknowledges that information, I'd like them to be sent along to the page in their initial URL request. I'd only like this to happen once per session.

The solution at which I've arrived has two, separate parts.

The first part is to create a rewrite rule that will take the incoming URL and append it as part of a query string.

Ex: https://www.incoming.com/somefile.aspx will be redirected to
     https://www.incoming.com/javascript.html?redir=https://www.incoming.com/somefile.aspx

The second part--which I believe is independent of the URL rewriting--involves using Javascript that takes the incoming query, checks whether the user has a specific session cookie. If the user does not have the session cookie set, it prompts them with some information. Once they acknowledge that information, they are sent along to the URL defined by the "redir=XXXX" name/value pair. If the user does have the session cookie set, it sends them along to the URL defined in the "redir=XXXX" name/value pair.

The Javascript part works as anticipated when I type https://www.incoming.com/javascript.html?redir=https://www.incoming.com/somefile.aspx into the browser's address bar.

The URL rewrite is where I'm running into problems.

The latest I've come up with is:

<rewrite><rules><rule name="TEST" stopProcessing="true"><match url="(.*)" /><action type="Redirect" url="javascript.html?redir={HTTP_HOST}/{R:1}" redirectType="Found" /></rule></rules></rewrite>

I've tried various URLs in the <action> as well with no luck. Examples:

<action type="Redirect" url="https://www.incoming.com/javascript.html?redir=https://{HTTP_HOST}/{R:1}" />
<action type="Redirect" url="https://www.incoming.com/javascript.html?redir=https://www.incoming.com/{R:1}" />

Unfortunately, the rewrite parses the value as null and leaves me with:
http://www.incoming.com/javascript.html?redir=null

Anyway, looking for suggestions and any assistance is appreciated.

Thanks!

Bug with certain URL

$
0
0

I have a linux web program that I access via rewrite.

There seems to be an issue when visiting certain URLs with rewrite, when I goto the server by it's host name all works as expected without issue.

The urls that don't have three full stops in together, eg: http://something.com/comp-master...1234567

In this case a 404 error is incorrectly returned

Thanks,
Kris

Forcing forward slash on urls and rewriting

$
0
0

Hi,

I've inherited a static site that has been set up with rewrites following this example:

<rule name="thank-you/"><match url="^thank-you(/)?$" /><action type="Rewrite" url="/thank-you.html" /></rule>


This pattern is repeated for each url, however I've found that the pattern hasn't been strict enough to ensure a trailing slash is always added. I've also found that the pages have been indexed in 3 locations

    mysite.com/thank-you.html
    mysite.com/thank-you
    mysite.com/thank-you/

I've made considerable progress in correcting this, but I'm getting issues where any other redirects have to be declared before the updated rules.

<rule name="Add Trailing Slash" stopProcessing="true"><match url=".*[^/]$" /><conditions logicalGrouping="MatchAll" trackAllCaptures="false"><add input="{REQUEST_FILENAME}" pattern=".+?\.\w+$" negate="true" /><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /></conditions><action type="Redirect" url="{ToLower:{R:0}}/" /></rule><rule name="Redirect HTML and PHP" stopProcessing="true"><match url="(.*).(html|htm|php)" /><conditions><add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /></conditions><action type="Redirect" url="{Tolower:{R:1}}/" appendQueryString="false" /></rule><rule name="Rewrite PHP"><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="{ToLower:{R:1}}.php" /></rule>


I'm also migrating all the static content to php, so there has to be a rule that captures any incoming url with the html extension and forwards it to the tidy url with the forward slash appended.

What I can't figure out is why I have to declare any other redirects before the above rules.

I'm fairly new to writing web.configs, so wonder if there is anything I've missed

Thanks

Viewing all 2482 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>