Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

web.config redirect all requests

Posted on 2014-11-07
9
Medium Priority
?
2,720 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 

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 2000 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

722 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