Reputation: 434
I am really struggling with getting the 301 redirects working on our server after deploying a new website. Everything I have tried has either resulted in a 500 error or just plain not working.
Below is the rewrite section excerpt from my web.config
file.
<rewrite>
<rules>
<rule name="wordpress" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<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="301 Redirect 1" stopProcessing="true">
<match url="^join$" />
<action type="Redirect" url="careers" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I was expecting to be able to redirect http://www.example.com/join to http://www.example.com/careers but I just get a 404 while accessing http://www.example.com/join.
I have checked and the URL Rewrite module is installed and enabled.
What am I doing wrong?
Upvotes: 4
Views: 857
Reputation: 488
Replace the code in your web.config file and update it with below code
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Upvotes: -1
Reputation: 6505
move your 301 redirect as first rule before the wordpress rule.
<rewrite>
<rules>
<rule name="301 Redirect 1" stopProcessing="true">
<match url="^join$" />
<action type="Redirect" url="careers" redirectType="Permanent" />
</rule>
<rule name="wordpress" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
Upvotes: 2