【问题标题】:301 redirect index.html to / or /index.php301将index.html重定向到/或/index.php
【发布时间】:2010-10-27 00:54:21
【问题描述】:

您好,

我刚刚将一个网站从 IIS 移动到 Apache,并且在重定向索引文件时遇到了一些麻烦,而不会导致无限循环。

这两个单独会导致循环-

重定向 301 /index.htm /index.php

重定向 301 /index.htm http://www.foo.com/

下面是我当前的 .htaccess 的副本。有人能帮我吗?我有一堆指向http://www.foo.com/index.htm 的链接,我想301 重定向到http://www.foo.com/

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /

########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|\.cfm|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section

Redirect 301 /a /administrator

【问题讨论】:

  • +1 从 IIS 迁移到 Apache

标签: apache mod-rewrite http-status-code-301


【解决方案1】:

你为什么要这样做?为什么不将 index.php 作为有效的索引扩展添加到您的 vhost/config 中

DirectoryIndex index.html index.php

然后删除HTML文件>

DirectoryIndex index.php

【讨论】:

    【解决方案2】:

    我猜你的目录索引设置为 index.html,它出现在 index.php 之前。然后你的http://www.foo.com/ 被解释为http://www.foo.com/index.html,它被重定向到http://www.foo.com/ - 因此循环。

    Here你得到了一些关于重定向不同方式的信息。

    【讨论】:

      【解决方案3】:

      您需要像这样检查 REQUEST_URI 的值:

      RewriteCond %{REQUEST_URI} ^/index.htm$     # If REQUEST_URI == "/index.htm"
      RewriteRule (.*) / [R=301,L]                # Then 301 redirect to "/"
      

      【讨论】:

        【解决方案4】:

        我同意 Kender 关于重定向循环的评论。可能是这样的方式

        DirectoryIndex notindex.html

        连同您的重定向,然后将实际的首页放在 notindex.html 中。如果该页面确实存在,我不清楚使用 /index.html 的人有什么问题?

        【讨论】:

        • example.comexample.com/index.html 进入同一个页面是谷歌所说的“重复内容”,它可能造成 SEO 问题。而且,除了可能的引用问题,我觉得很难看。一个网址,一页。
        【解决方案5】:

        我还不能添加超链接,因为我是新用户,所以当我输入“foo”时,假设这是整个 URL...

        若要在没有循环的情况下将 foo/index.php 重定向到 foo/,请使用另一个重写规则:

        RewriteRule index.php foo/ [R=301]
        

        您可能需要使用 /index.php,具体取决于您的 RewriteBase 设置为(以及您有多少个目录中有 index.php)。

        【讨论】:

          猜你喜欢
          • 2016-12-26
          • 2014-01-14
          • 1970-01-01
          • 2014-09-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-06
          相关资源
          最近更新 更多