2009-05-18 156 views
6

問候,301重定向的index.html到/或的index.php

我剛剛搬進從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 
+0

+1從IIS移開到Apache – eleven81 2009-05-18 13:35:59

+0

@ eleven81 - 尼斯。 – 2009-05-18 15:47:31

回答

6

你爲什麼這樣做?爲什麼不給你的虛擬主機/ config中添加的index.php作爲一個有效的索引擴展

DirectoryIndex index.html index.php 

,然後刪除HTML文件>

DirectoryIndex index.php 
0

我坎德的有關重定向的評論表示贊同循環。也許一輪的辦法是讓

的DirectoryIndex notindex.html

與你一起重定向,然後把實際的頭版中notindex.html。我不清楚如果該頁面真的存在,使用/index.html的人有什麼問題?

0

我不允許添加超鏈接呢,因爲我是一個新用戶,所以當我輸入「富」只是假設這就是整個網址...

重定向富/指數。 PHP來富/不循環,可使用另一種重寫規則:

​​

您可能需要使用的index.php取決於你的RewriteBase設置爲(和你有多少目錄有一個的index.php) 。

1

您需要檢查REQUEST_URI的值是這樣的:

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