【问题标题】:How to redirect my deleted links如何重定向我已删除的链接
【发布时间】:2012-04-14 10:43:22
【问题描述】:

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

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

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>

【问题讨论】:

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


    【解决方案1】:
    • 启用 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/ 开头的链接都已永久移至/(主页),您的排名不会受到任何负面影响。

    【讨论】:

    • 我已经有了这些行 Options -MultiViews -Indexes +FollowSymlinks RewriteCond %{http_host} ^onlinetvjunction.com [NC] RewriteRule ^(.*)$ onlinetvjunction.com/$1 [R=301,NC] RewriteRule ^golmagico/(.*)$ en/index.php?title=$1 [PT,L,QSA] 现在告诉我把你的台词放在哪里?
    • 首先不要在 cmets 中发布任何代码。我将您的代码复制/粘贴到您的问题中,并且必须告诉您所有代码都有问题。你确定它对你有用吗?
    • 好吧,这看起来比您在评论中发布的要好。您需要在最后一个 RewriteRule 之后添加这一行 RewriteRule ^article/ / [NC,L,R=301],它看起来像 RewriteRule ^recent/...
    • @JitendraRawal 如果有效,请将其标记为已回答meta.stackexchange.com/questions/5234/…
    【解决方案2】:

    试着把它放在你的 .htaccess 中

    ErrorDocument 404 http://www.mydomain.com
    

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

    或者你可以试试:

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

    将所有对文章文件夹的请求重定向到根目录

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 2011-02-20
      • 2015-05-24
      • 2021-03-20
      • 1970-01-01
      相关资源
      最近更新 更多