如何将myforum.com/index.php永久重定向到myforum.com

时间:2012-02-15 16:00:02

标签: php redirect windows-server-2008 iis-7.5 forum

我在IIS 7.5上使用Windows Server 2008上的MYBB php论坛

我想将index.php永久重定向到主网址

我该怎么做?

实施例

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

将被重定向到

http://forum.monstermmorpg.com

我该怎么做?谢谢。

我正在使用的重写规则

    <?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>

2 个答案:

答案 0 :(得分:2)

如果您使用web.config文件并安装了IIS重写模块,则此规则应该可以正常工作

<?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>

答案 1 :(得分:0)

在index.php上写下这样的东西:

//> header 302
if ($_SERVER['REQUEST_URI']=='/index.php')
 header('Location: /');

//> header 301
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: /' );