簡體   English   中英

301將index.html重定向到/或/index.php

[英]301 redirect index.html to / or /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

你為什么做這個? 為什么不將index.php作為有效的索引擴展添加到vhost / config

DirectoryIndex index.html index.php

然后刪除HTML文件>

要么

DirectoryIndex index.php

我猜你的目錄索引設置為index.html,它發生在index.php之前。 然后您的http://www.foo.com/被解釋為http://www.foo.com/index.html ,它被重定向到http://www.foo.com/ - 因此循環。

在這里,您獲得了有關重定向不同方式的一些信息。

您需要檢查REQUEST_URI的值,如下所示:

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

我同意Kender關於重定向循環的評論。 可能是這樣的方式

DirectoryIndex notindex.html

與您的重定向一起,然后將實際的首頁放在notindex.html中。 如果該頁面確實存在,我不清楚使用/index.html的人有什么問題?

我還不允許添加超鏈接,因為我是新用戶,因此當我輸入“foo”時,只需假設整個URL ...

要將foo / index.php重定向到沒有循環的foo /,請使用另一個重寫規則:

RewriteRule index.php foo/ [R=301]

您可能需要使用/index.php,具體取決於您的RewriteBase設置為什么(以及index.php中有多少個目錄)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM