Search code examples
phphttp-redirectwindows-server-2008iis-7.5forum

How to permanently redirect myforum.com/index.php to myforum.com


I am using MYBB php forum at windows server 2008 on IIS 7.5

I want to permanently redirect index.php to main url

How can i do that ?

Example

http://forum.monstermmorpg.com/index.php

Will be redirected to

http://forum.monstermmorpg.com

How can i do that ? Thank you.

The rewrite rules i am using

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^([^&amp;]*)&amp;(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="http://forum.monstermmorpg.com/{R:1}?{R:2}" appendQueryString="true" redirectType="Permanent" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^sitemap\-([^./]+)\.xml$" />
                    <action type="Rewrite" url="misc.php?google_seo_sitemap={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 3" stopProcessing="true">
                    <match url="^Forum\-([^./]+)$" />
                    <action type="Rewrite" url="forumdisplay.php?google_seo_forum={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 4" stopProcessing="true">
                    <match url="^Thread\-([^./]+)$" />
                    <action type="Rewrite" url="showthread.php?google_seo_thread={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 5" stopProcessing="true">
                    <match url="^Announcement\-([^./]+)$" />
                    <action type="Rewrite" url="announcements.php?google_seo_announcement={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 6" stopProcessing="true">
                    <match url="^User\-([^./]+)$" />
                    <action type="Rewrite" url="member.php?action=profile&amp;google_seo_user={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 7" stopProcessing="true">
                    <match url="^Calendar\-([^./]+)$" />
                    <action type="Rewrite" url="calendar.php?google_seo_calendar={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Imported Rule 8" stopProcessing="true">
                    <match url="^Event\-([^./]+)$" />
                    <action type="Rewrite" url="calendar.php?action=event&amp;google_seo_event={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Solution

  • If your using a web.config file and have the IIS Rewrite Module installed, this rule should work

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
         <modules runAllManagedModulesForAllRequests="true" />
            <rewrite>
                <rules>
                    <rule name="CanonicalHostNameRule" stopProcessing="true">
                      <match url="^(\w*/)?index\.php" />
                <conditions>
                <add input="{HTTP_HOST}" pattern="forum\.monstermmorpg\.com$" />
                </conditions>
                       <action type="Redirect" url="http://forum.monstermmorpg.com/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
      </system.webServer>
    </configuration>