如何重定向我删除的链接

时间:2012-03-30 18:03:20

标签: apache .htaccess redirect http-status-code-404 http-status-code-301

我有我的网站在哪里我有一个文章目录,但现在我已删除该文章目录和谷歌网站管理员正在显示这些链接未找到,这对我的搜索结果有负面影响。

请帮我重定向这样的所有链接

http://www.mydomain.com/article/arts-entertainment/bradley-spalter-songs-getting-past-emotionally-charged-barriers/

http://www.mydomain.com

当前.htaccess文件:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 day"
ExpiresByType text/plain "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 15 days"
</IfModule>
## EXPIRES CACHING ##
Options -MultiViews -Indexes +FollowSymlinks
RewriteCond %{http_host} ^mydomain.com [NC]

RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]

RewriteRule ^golmagico/(.*)$ en/index.php?title=$1 [PT,L,QSA]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

ErrorDocument 401 /default_error.php
ErrorDocument 402 /default_error.php
ErrorDocument 403 /default_error.php
ErrorDocument 404 /default_error.php
<IfModule mod_php5.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>

<IfModule sapi_apache2.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^detailed/recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1&viewtype=detailed
RewriteRule ^detailed/viewed/?([^/\.]+)?/?$ video.php?category=viewed&page=$1&viewtype=detailed
RewriteRule ^detailed/recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1&viewtype=detailed
RewriteRule ^detailed/discussed/?([^/\.]+)?/?$ video.php?category=discussed&page=$1&viewtype=detailed
RewriteRule ^detailed/favorites/?([^/\.]+)?/?$ video.php?category=favorites&page=$1&viewtype=detailed
RewriteRule ^detailed/rated/?([^/\.]+)?/?$ video.php?category=rated&page=$1&viewtype=detailed
RewriteRule ^detailed/featured/?([^/\.]+)?/?$ video.php?category=featured&page=$1&viewtype=detailed
RewriteRule ^detailed/random/?([^/\.]+)?/?$ video.php?category=random&page=$1&viewtype=detailed
RewriteRule ^recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1
RewriteRule ^videos/?([^/\.]+)?/?$ video.php?category=recent&page=$1
RewriteRule ^recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1

</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>

2 个答案:

答案 0 :(得分:0)

尝试将其放入.htaccess

ErrorDocument 404 http://www.mydomain.com

它会将所有404重定向到您的域名。

或者您可以尝试:

RewriteRule ^articles/.*?$ / [NC]

将所有对articles文件夹的请求重定向到root

答案 1 :(得分:0)

  • 启用mod_rewrite
  • 启用.htacccess
  • 在DOCUMENT_ROOT
  • 下创建.htaccess文件

并将此代码放在那里:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^article/ / [NC,L,R=301]

R=301会告诉Google和其他搜索机构,以/article/开头的所有链接都已永久移至/(主页),您不会对您的排名产生任何负面影响