出于某种原因,我突然无法让我的Redirect 301s工作。 .htaccess文件如下。我只粘贴了第10个Redirect 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 ***********************
答案 0 :(得分:0)
解释是您无法在Redirect
或RedirectMatch
语句的模式中与查询字符串进行匹配。声明:
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
而不是查询字符串(?
之后的所有内容)。您需要使用mod_rewrite中的%{QUERY_STRING}
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
,您可能会发现自己被重定向到未明确制作的意外网址。重写规则(mod_rewrite)和重定向(mod_alias)可能相互干扰,因为这两个模块应用于URL文件映射引擎的不同点,并且两个模块最终可能会破坏相同的URI。如果发生这种情况,你应该坚持只使用mod_rewrite进行重定向,因为你需要重写引擎来匹配查询字符串。