Solved

web.config redirect all requests

Posted on 2014-11-07
9
2,265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

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 11

Expert Comment

by:Joe Klimis
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

617 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