2

出于某种原因,我突然无法让我的 Redirect 301 正常工作。.htaccess 文件如下。我只粘贴了第 10 个重定向 301 命令,但有超过 100 个。

301 重定向都具有相同的格式,但列出的前六个无效。最后四个(后跟“ ** ”)按预期运行。我看不出任何解释。

有任何想法吗?

Options +FollowSymLinks

## Mod_rewrite in use.

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 base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%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})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

########## Begin - Custom redirects
RewriteCond %{HTTP_HOST} ^www\.caringcompanion\.net [NC]
RewriteRule (.*) http://caringcompanion.net/$1 [R=301,L,NC]

Redirect 301 /homecare/10-caring-companion/index.php?option=com_content&view=article&id=89&Itemid=75 http://www.caringcompanion.net/concord-ma

Redirect 301 /homecare/10-caring-companion/index.php?option=com_content&view=article&id=94&Itemid=75 http://caringcompanion.net/cambridge-ma

Redirect 301 /homecare/10-caring-companion/index.php?option=com_content&view=article&id=94&Itemid=74 http://caringcompanion.net/cambridge-ma

Redirect 301 /index.php?option=com_content&view=article&id=94:cambridge-ma-home-care-elderly-caregivers&catid=38:cambridge&Itemid=74 http://caringcompanion.net/cambridge-ma

Redirect 301 /index.php?option=com_content&view=article&id=93:acton-ma-home-care-elderly-caregivers&catid=34:acton&Itemid=70 http://caringcompanion.net/acton-ma

Redirect 301 /homecare/10-caring-companion/index.php?option=com_content&view=article&id=93&Itemid=70 http://caringcompanion.net/acton-ma

Redirect 301 /homecare-ma/ma/index.php?option=com_content&view=article&id=52&Itemid=158 http://caringcompanion.net/homecare-massachuetts-maine-new-hampshire

Redirect 301 /tag/71-biophilia http://caringcompanion.net/services/client-care-coordinators  ***********

Redirect 301 /ccc-copyright-notice/73-caring-companion/services/127-alzheimers-dementia-services http://caringcompanion.net/services/alzheimers-dementia   *********

Redirect 301 /index.php/component/content/article/73-caring-companion/services/127-alzheimers-dementia-services http://caringcompanion.net/services/alzheimers-dementia  ******

Redirect 301 /jblog/118-alzheimers-dementia http://caringcompanion.net/services/alzheimers-dementia   ***********************
4

1 回答 1

0

解释是您无法匹配RedirectorRedirectMatch语句模式中的查询字符串。该声明:

Redirect 301 /homecare/10-caring-companion/index.php?option=com_content&view=article&id=89&Itemid=75 http://www.caringcompanion.net/concord-ma

实际上试图匹配这个 URI:

/homecare/10-caring-companion/index.php%3Foption=com_content%26view=article%26id=89%26Itemid=75

而不是查询字符串(之后的所有内容?)。您需要使用%{QUERY_STRING}mod_rewrite 中的 var 来匹配它。所以是这样的:

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=89&Itemid=75$ 
RewriteRule ^/?homecare/10-caring-companion/index\.php$ http://caringcompanion.net/concord-ma [L,R=301]

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=94&Itemid=75$ [OR]
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=94&Itemid=74$
RewriteRule ^/?homecare/10-caring-companion/index\.php$ http://caringcompanion.net/cambridge-ma [L,R=301]

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=94:cambridge-ma-home-care-elderly-caregivers&catid=38:cambridge&Itemid=74$
RewriteRule ^/?index\.php$ http://caringcompanion.net/cambridge-ma [L,R=301]

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=93:acton-ma-home-care-elderly-caregivers&catid=34:acton&Itemid=70$
RewriteRule ^/?index\.php$ http://caringcompanion.net/action-ma [L,R=301]

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=93&Itemid=70$ 
RewriteRule ^/?homecare/10-caring-companion/index\.php$ http://caringcompanion.net/action-ma [L,R=301]

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=52&Itemid=158$
RewriteRule ^/?homecare-ma/ma/index.php$ http://caringcompanion.net/homecare-massachuetts-maine-new-hampshire [L,R=301]

根据Redirect您拥有的其他 's,您可能会发现您被重定向到您未明确创建的意外 URL。重写规则 (mod_rewrite) 和重定向 (mod_alias) 可能会相互干扰,因为这两个模块应用在 URL 文件映射引擎的不同点,并且两个模块最终可能会破坏相同的 URI。如果发生这种情况,您应该坚持只使用 mod_rewrite 进行重定向,因为您需要重写引擎来匹配查询字符串。

于 2013-07-04T00:17:24.263 回答