• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 97
  • Last Modified:

URL rewrite not working

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
billium99
Asked:
billium99
  • 5
  • 5
1 Solution
 
Steve BinkCommented:
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
 
billium99Author Commented:
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
 
Steve BinkCommented:
Nothing else pops out at me.  Have you tried enabling tracing to see what is being matched or not matched?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Steve BinkCommented:
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
 
billium99Author Commented:
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
 
Steve BinkCommented:
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
 
billium99Author Commented:
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
 
Steve BinkCommented:
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
 
billium99Author Commented:
Keeping this open while I put out other fires - thanks for your patience...I hope to be back to this today/tomorrow.
0
 
billium99Author Commented:
I think this was it. It's difficult to know now, as we used a WordPress Redirect plugin that provided the needed behavior.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now