我们最近完全重新设计了我们的网站并迁移到不同的 CMS 系统。我正在尝试基于旧的 Web 结构设置重定向,通过识别数百个可能的 URL 中的任何一个字符串来将所有内容定向到我们的新站点。出于本文的目的,我将重点关注字符串“_xdc.php”。
示例:我想http://www.mysite.com/_xdc.php?somerandomstring
将 (301) 重写为http://www.mysite.com
.
目前我正在使用这个:
RewriteRule ^.*xdc.*$ http://www.mysite.com [R=301,L]
只要它确实重定向到站点主页,此方法就可以工作。不过有两个问题。
第一个问题: ? 之后的胡言乱语 正在附加,我不希望它。基本上:
http://www.mysite.com/_xdc.php?somerandomstring
变成http://www.mysite.com/?somerandomstring
但我希望它是唯一的http://www.mysite.com
第二个问题:如果我创建了一个包含字母“xdc”的新页面,它将被重定向。但是,当我尝试限制
^.*_xdc.php*
重写时根本不起作用。我确定这与 _ 和 . 在“_xdc.php”中,但我不确定如何强制将这些特殊字符读取为纯文本而不是代码......
我错过了什么?我确信它很明显,但我仍然是 htaccess 的菜鸟,所以我非常感谢你的帮助!
如果需要,我在下面包含了我的完整 htaccess:
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
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
# redirect any variations of a specific character string to a specific address
RewriteRule ^calendar http://www.mysite.com [R=301,L]
RewriteRule ^.*xdc.*$ http://www.mysite.com [R=301,L]
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
RewriteBase /deloro
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php [L]
ErrorDocument 404 http://www.mysite.com/index.php?option=com_content&view=article&id=60