【问题标题】:Redirect to new url using .htaccess使用 .htaccess 重定向到新的 url
【发布时间】:2015-05-12 15:24:10
【问题描述】:

我正在尝试进行 url 重定向,但我拥有 .htaccess 文件的方式似乎不起作用。我需要使用特定的位置或格式进行重定向吗?

下面是我的 .htaccess

# 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>

Redirect 301 /research/report-listings/ http://example.com/research/research-portfolio/

# END WordPress

# BEGIN wtwp_cache
# END wtwp_cache

# BEGIN wtwp_security
# END wtwp_security

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您可能不想将 mod_alias 指令与 mod_rewrite 指令混合使用。两个模块最终都将应用于同一个请求,并且您最终可能会遇到一些不稳定的重定向。如果你有 Wordpress 之类的规则,最好只使用 mod_rewrite。

    注意:顺序很重要

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^research/report-listings/(.*)$ http://example.com/research/research-portfolio/$1 [L,R=301]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    【讨论】:

    【解决方案2】:

    尝试将您的 Redirect 指令放在 &lt;IfModule mod_alias.c&gt;...&lt;/IfModule&gt; 块内。然后,确保您已安装并启用 mod_alias.c:

    apache2ctl -M  #This is for Linux systems
    

    【讨论】:

    • 我试过了,但它似乎仍然不起作用。当我转到该页面时,它不遵循重定向它只是给了我一个 404
    • Here's 你遇到的同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2019-10-15
    • 2017-09-25
    • 1970-01-01
    • 2015-09-14
    • 2022-06-11
    相关资源
    最近更新 更多