Solved

web.config redirect all requests

Posted on 2014-11-07
9
1,190 Views
Last Modified: 2014-12-11
Is it possible to redirect all my web requests to index.htm ? From looking at forums, Ive managed to get together:-
<?xml version="1.0"?>

<configuration>
    <system.web>
        <rule name="rule 1g" stopProcessing="true">
	        <match url="."  />
	        <action type="Rewrite" url="/index.php"  />
        </rule>
    </system.web>
</configuration>

Open in new window


However all I get is:-
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Im hoping that once the page has been redirected I can query the requested page,
0
Comment
Question by:tonelm54
  • 3
  • 3
9 Comments
 
LVL 28

Expert Comment

by:becraig
ID: 40428967
This should work:
    <configuration>
       <system.webServer>
          <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
             <add wildcard="*" destination="/index.php" />
          </httpRedirect>
       </system.webServer>
    </configuration>

Open in new window


I am assuming of course that you are asking to redirect all requests to index.php ?
0
 

Author Comment

by:tonelm54
ID: 40428995
When I try your example I dont get the same error but instead get:-
This webpage has a redirect loop
0
 
LVL 28

Expert Comment

by:becraig
ID: 40429019
Oops my bad I forgot to specifiy a resource type (*.htm)

    <configuration>
       <system.webServer>
          <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
             <add wildcard="*.htm" destination="/index.php" />
          </httpRedirect>
       </system.webServer>
    </configuration>
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:tonelm54
ID: 40429035
I was hoping to do all pages, so using your example something like this:-
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
            <add wildcard="index.php" StopProcessing="true" />
            <add wildcard="*.jpg" StopProcessing="true" />
            <add wildcard="*.png" StopProcessing="true" />
            <add wildcard="*.js" StopProcessing="true" />
            <add wildcard="*" destination="/index.php" />
        </httpRedirect>
    </system.webServer>
</configuration>

Open in new window


Sorry to keep hasseling you, Im just finding resources very slim, and help files not helpful on web.config files
0
 
LVL 10

Expert Comment

by:JoeKlimis
ID: 40446974
Hi

The following should redirect all pages , without having to specify all of them
Which version of iis are you using  ?
and you may also find this Microsoft Web Page  show how to do this through the GUI  

<configuration>
 <location>
    <system.webServer>
      <httpRedirect enabled="true" destination="http://www.newWebSite.com/" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

Open in new window

0
 

Author Comment

by:tonelm54
ID: 40449868
The problem I have found with this redirect is that it redirects everything to index.php, including index.php and any js or css files I have
0
 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
ID: 40468909
We can use URL rewrite for this ( I think the below example should work:


So we simply match the wildcard on the url and create negate conditions for the files you want to exclude
<rewrite>
  <rules>
    <rule name="Rewrite All" enabled="true" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{REQUEST_URI}" pattern="^index.php" ignoreCase="true" negate="true" />
        <add input="{REQUEST_URI}" pattern="*.jpg" ignoreCase="true" negate="true" />
        <add input="{REQUEST_URI}" pattern="*.png" ignoreCase="true" negate="true" />
        <add input="{REQUEST_URI}" pattern="*.js" ignoreCase="true" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com/index.php" />
    </rule>
  </rules>
</rewrite>

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now