【问题标题】:Remove index.php and add 301 redirects in .htaccess (ExpressionEngine)删除 index.php 并在 .htaccess (ExpressionEngine) 中添加 301 重定向
【发布时间】:2012-07-24 03:29:52
【问题描述】:

客户有一个表达式引擎站点,并希望删除“index.php”。单独这样做会降低他的网站 SEO 排名,因为它会更改所有 URL。因此,我们希望通过向所有页面添加 301 来保留链接权益和社交网络共享计数。

我知道如何删除 index.php 并且知道如何重定向(我认为),但是当我同时使用它们时,服务器会引发重定向循环。我的逻辑是扭曲的。我在这里错过了什么?

这是我正在使用的:

# Redirect attempt
Redirect 301 /index.php/feature/article/ http://domain.com/feature/article/

# EE index.php rewrite
RewriteCond $1 !^(index\.php|js|path\.php|press_releases|rear|robots\.txt|text\.html|themes) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L] 

【问题讨论】:

    标签: php .htaccess mod-rewrite expressionengine


    【解决方案1】:

    如果实际请求是针对/index.php/ URL,您只想重定向。将您的 Redirect 指令更改为:

    # Redirect attempt
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
    RewriteRule ^/?index.php/feature/article/(.*)$ http://domain.com/feature/article/$1 [R=301,L]
    

    此条件与服务器收到的实际请求匹配,而不是 URI(可以被第二条规则重写)。

    【讨论】:

    • 完全有道理。万分感谢。如果我最后有一个变量怎么办。类似 '/feature/article/{variable_article_name}/' 我如何将 {variable_article_name} 从请求“移动”到重写?
    • 现在我们开始讨论了!效果很好。感谢您的洞察力。
    猜你喜欢
    • 2013-11-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2012-04-03
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    相关资源
    最近更新 更多