Solved

web.config redirect all requests

Posted on 2014-11-07
9
1,363 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 29

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 29

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 29

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
URL Redirect using IIS v8 4 24
Server Error 11 47
How to add <appSettings> to the webconfig file 2 21
SSRS troubles 4 20
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

12 Experts available now in Live!

Get 1:1 Help Now