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
Solved

URL rewrite not working

Posted on 2015-02-07
10
66 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

837 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