Solved

URL rewrite not working

Posted on 2015-02-07
10
57 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 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

19 Experts available now in Live!

Get 1:1 Help Now