【问题标题】:Redirecting 404s using 301 redirects with .htaccess使用 301 重定向和 .htaccess 重定向 404
【发布时间】:2015-03-20 07:29:20
【问题描述】:

我正在编辑的 .htaccess 文件包含以下用于将 http://www.example.com 重定向到 http://example.com 的代码:

AddHandler fcgid54-script .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress    

在没有从头开始编写新的 .htaccess 文件的情况下,我希望重定向一些返回 404 的其他页面。我尝试了以下方法,但没有成功:

AddHandler fcgid54-script .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

301 Redirect /blank/blah/page/ http://example.org/blank/blah/

# END WordPress

我还尝试了许多其他迭代,但到目前为止没有任何效果。

【问题讨论】:

    标签: .htaccess mod-rewrite redirect


    【解决方案1】:

    不要将mod_rewrite 规则与mod_alias 混合在一起,并在内部 WP 规则之前保留 301:

    AddHandler fcgid54-script .php
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^blank/blah/page/?$ http://example.org/blank/blah/ [L,NC,R=301]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      试试这个,它会起作用的:

      ErrorDocument 404 http://www.example.com/abc.html
      

      通过在htaccess 文件中添加这一行,返回 404 的页面将被转发到指定的 url。比如http://www.example.com/abc.html

      【讨论】:

        猜你喜欢
        • 2014-08-29
        • 2018-05-10
        • 1970-01-01
        • 2011-05-01
        • 2011-01-03
        • 2012-03-10
        • 2021-07-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多