6

问候,

我刚刚将一个网站从 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
4

5 回答 5

6

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

DirectoryIndex index.html index.php

然后删除HTML文件>

或者

DirectoryIndex index.php
于 2009-05-18T13:32:22.633 回答
3

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

在这里,您可以获得一些有关重定向不同方式的信息。

于 2009-05-18T13:31:52.137 回答
1

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

RewriteCond %{REQUEST_URI} ^/index.htm$     # If REQUEST_URI == "/index.htm"
RewriteRule (.*) / [R=301,L]                # Then 301 redirect to "/"
于 2012-02-17T21:06:34.107 回答
0

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

DirectoryIndex notindex.html

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

于 2009-05-18T13:35:54.310 回答
0

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

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

RewriteRule index.php foo/ [R=301]

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

于 2009-05-26T10:43:15.277 回答