Reputation: 75
I have a script in place that replaces example.com/folder/index.php/pagename
with example.com/pagename
.
But example.com/pagename
technically doesn't exist - so if someone navigates to it they get a 404.
I tried to add a redirect in my web.config file that looks like:
<rewrite>
<rules>
<rule name="my redirect" stopProcessing="true">
<match url="pagename" />
<action type="Redirect" url="http://www.example.com/folder/index.php/pagename/" redirectType="permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
But it's resulting in a redirect loop. I noticed that if I change the final URL to something different like example.com/pagenamealternate
that it works just fine.
Can anyone tell me if there's a handy condition or alternative way of solving this problem?
Upvotes: 3
Views: 44
Reputation: 11222
You are getting a redirect loop because your pattern pagename
also matches the target URL, which has pagename
in it.
Change your match url to ^pagename$
, now the rewrite rule only kicks in for requests with the exact url: example.com/pagename
, you may want to allow additional text after the pagename, then use: ^pagename
as the match pattern.
The ^
in a regular expression means the beginning of a string, this works because the rewrite engine looks at everything after the hostname part.
Also consider a rewrite action rather than a redirect.
Upvotes: 1