Solved

URL rewrite not working

Posted on 2015-02-07
10
64 Views
Last Modified: 2015-05-26
Hi All,

I have a URL Rewrite set of rules in web.config for a Joomla website running in IIS7.5 on Win Server 2008 R2.

For the life of me, I cannot get a simple 301 redirect to work, either as a direct rule, or in a separate redirect maps file.

Here is my current web.config code. Specifically, why can I not see the royallee rule functioning?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>

      <rules>
                
               
                <rule name="CanonicalHostNameRule1">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="^www\.seleneriverpress\.com$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.seleneriverpress.com/{R:1}" />
                </rule>



                <rule name="Imported Rule 1">
                    <match url=".*" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="base64_encode[^(]*\([^)]*\)" ignoreCase="false" />
                        <add input="{QUERY_STRING}" pattern="(&lt;|%3C)([^s]*s)+cript.*(>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                    </conditions>
                    <action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url=".*" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{URL}" pattern="^/index\.php" ignoreCase="false" negate="true" />
                        <add input="{URL}" pattern="/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
                <rule name="wordpress" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
                <rule name="promo">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="https://seleneriverpress.com/srp-promo" />
                    </conditions>
                    <action type="Rewrite" url="https://seleneriverpress.com/blog/srp-promo" />
                </rule>
                <rule name="royallee" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="https://www.seleneriverpress.com/products/by-dr-lee" />
                    <action type="Redirect" url="https://www.seleneriverpress.com/products/trending-authors/dr-royal-lee" />
                </rule>
</rules>
    </rewrite>
  </system.webServer>
</configuration>

Open in new window


If I go to the actual URL:

https://www.seleneriverpress.com/products/by-dr-lee

No rewrite takes place. It just 404's.

But all the other rules appear to be working. Any idea what the problem is?

This is WAMP running PHP for Joomla, but adding redirects to htaccess doesn't work either, and my understanding is that I should be using IIS rewrites for this type of thing.

What am I doing wrong?

Thanks

Bill
0
Comment
Question by:billium99
  • 5
  • 5
10 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40597013
In this rule:
                <rule name="royallee" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="https://www.seleneriverpress.com/products/by-dr-lee" />
                    <action type="Redirect" url="https://www.seleneriverpress.com/products/trending-authors/dr-royal-lee" />
                </rule>

Open in new window

The <match> url attribute should not include the protocol or host.  Change it to include only "/products/by-dr-lee".
0
 
LVL 1

Author Comment

by:billium99
ID: 40597137
Hi Steve,

Hmm - I've tried these two permutations with same 404 result:

<rule name="royallee" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="/products/by-dr-lee" />
                    <action type="Redirect" url="https://www.seleneriverpress.com/products/trending-authors/dr-royal-lee" />
                </rule>

<rule name="royallee" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="/products/by-dr-lee" />
                    <action type="Redirect" url="/products/trending-authors/dr-royal-lee" />
                </rule>

Any idea why this still won't work?

Thanks for your time

Bill
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40597279
Nothing else pops out at me.  Have you tried enabling tracing to see what is being matched or not matched?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40597292
One other thing:
                <rule name="wordpress" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>

Open in new window

That rule may be firing before your "royallee" rule, and will interfere with the latter's execution.
0
 
LVL 1

Author Comment

by:billium99
ID: 40597379
Is it normal for the request tracing to create large, confusing log files?

I mean I can confirm IIS is creating trace log files - I already have a few thousand since following the steps to activate it, but I'm not sure what I'm reading. I just did a string search of the full directory of these log files. They all seem to have one instance only:

<EventData>
  <Data Name="ContextId">{00000000-0000-0000-F60B-0080000000F3}</Data>
  <Data Name="Input">{QUERY_STRING}</Data>
  <Data Name="ExpandedInput"></Data>
  <Data Name="MatchType">0</Data>
  <Data Name="Pattern">/products/by-dr-lee</Data>
  <Data Name="Negate">false</Data>
  <Data Name="Succeeded">false</Data>
 </EventData>

And there are a huge number of these events, but for seemingly random URLs from this site

Sorry - I'm struggling to understand how I can tell how this is failing. I just disabled all other rewrite rules except this drlee rule, and it still failed.

Bill
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40597393
FRT will generate a log for each request that comes to the server.  What you're seeing in that directory is a compilation of all requests.  You need to find the log for YOUR specific test and examine it.  If you can isolate that file and post it here, we can take a look to help analyze it.  Also, opening it in IE will also help with legibility.
0
 
LVL 1

Author Comment

by:billium99
ID: 40606994
Sorry for the delay. I have a server down which has pushed all other issues aside.

Well I've looked through numerous of these FRT files, and I cannot find my "test" URL anywhere in the event logs.

Could that, in itself, mean something (assuming I'm typing the right "bad" URL, which I've triple checked)?

Bill
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40607351
It could mean that FRT is not firing on your requests.  Try deleting all existing reports, do the test, then quickly turn off FRT.  If you can't isolate your server from the public, do the test during a low-traffic period.  

If you still can't find a trace for it, verify it is configured to fire for this URL.
0
 
LVL 1

Author Comment

by:billium99
ID: 40616537
Keeping this open while I put out other fires - thanks for your patience...I hope to be back to this today/tomorrow.
0
 
LVL 1

Author Closing Comment

by:billium99
ID: 40797391
I think this was it. It's difficult to know now, as we used a WordPress Redirect plugin that provided the needed behavior.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

773 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