Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

URL rewrite not working

Posted on 2015-02-07
10
Medium Priority
?
77 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
[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
  • 5
  • 5
10 Comments
 
LVL 51

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 51

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 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 51

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 51

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
Suggested Courses

618 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