【发布时间】:2011-02-26 06:20:38
【问题描述】:
我在进行 301 重定向时遇到了 2 个问题。我在该域上拥有的旧 CMS 没有被使用,我正试图弄清楚如果有匹配项如何正确重定向。
1) 从 url 中删除查询字符串并进行重定向。 以下是尝试访问的 urls 搜索引擎应该重定向到主页 index.php
示例:http://www.mysite.com/?dispatch=products.search&features_hash=P2
或
例如:http://www.mysite.com/index.php?dispatch=products.search&features_hash=V9
或
这是我目前尝试的代码,但不起作用:
RewriteCond %{QUERY_STRING} ^dispatch$
RewriteRule ^(.*)$ http://www.mysite.com/$1? [R=301,L]
2) 我遇到的另一个问题是由于某种原因,我的网站通过 url= 参数在搜索引擎中存在重复项。例如,
基本上它们是相同的页面,但是当您考虑到我有类别页面和其他单个页面都通过 url= 访问时,这是不对的。基本上我想要做的是将 301 返回到主 mysite.com 为此,我尝试了以下代码,但也不起作用:
RewriteCond %{QUERY_STRING} ^url$
RewriteRule ^(.*)index.php$ http://www.mysite.com/$1? [R=301,L]
*****-----已编辑:------******* 完成 htaccess 文件:
Options -Indexes
Options +SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^([a-z0-9/-]+)-p-([0-9]+).html$ my-pages.php [NC,L,QSA]
</IfModule>
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*iframe.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteCond %{QUERY_STRING} (;|'|"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if).* [NC]
RewriteCond %{QUERY_STRING} ^(.*)/self/(.*)$ [NC]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteRule ^(.*)$ error_page.php [F,L]
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
ErrorDocument 400 /error_page.php?error_id=400
ErrorDocument 401 /error_page.php?error_id=401
ErrorDocument 403 /error_page.php?error_id=403
ErrorDocument 404 /error_page.php?error_id=404
ErrorDocument 405 /error_page.php?error_id=405
ErrorDocument 408 /error_page.php?error_id=408
ErrorDocument 415 /error_page.php?error_id=415
ErrorDocument 500 /error_page.php?error_id=500
ErrorDocument 501 /error_page.php?error_id=501
ErrorDocument 502 /error_page.php?error_id=502
ErrorDocument 503 /error_page.php?error_id=503
ErrorDocument 505 /error_page.php?error_id=505
ErrorDocument 504 /error_page.php?error_id=504
<FilesMatch "\.(inc|tpl|h|ihtml|sql|ini|conf|class|bin|spd|theme|module|exe)$">
deny from all
</FilesMatch>
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww-perl [OR]
RewriteCond %{QUERY_STRING} tool25 [OR]
RewriteCond %{QUERY_STRING} cmd.txt [OR]
RewriteCond %{QUERY_STRING} cmd.gif [OR]
RewriteCond %{QUERY_STRING} r57shell [OR]
RewriteCond %{QUERY_STRING} c99 [OR]
<Files 403.shtml>
order allow,deny
allow from all
</Files>
【问题讨论】:
-
给出一些示例 URL 和目标 URL。
-
@Zimbabao:完成。根据您的要求添加它
标签: .htaccess mod-rewrite