.htaccess重定向,URL友好(mod_rewrite)

时间:2016-05-05 10:34:14

标签: apache .htaccess mod-rewrite url-redirection

我在我的网址中使用RewriteRule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&page=$2 [L,QSA,NC]

现在我需要创建301重定向。所以我这样做:

Redirect 301 /port/reestruturacao-financeira http://website.com/port/reestruturacao-corporativa/

结果是错误的:

http://website.com/port/reestruturacao-corporativa//?lang=port&page=reestruturacao-financeira

我该如何解决?重定向

http://website.com/port/reestruturacao-corporativa/

http://website.com/port/reestruturacao-corporativa/

1 个答案:

答案 0 :(得分:1)

您需要在其他内部重写规则之前保留重定向mod_rewrite规则并仅使用RewriteEngine On RewriteRule ^port/reestruturacao-financeira /port/reestruturacao-corporativa/? [L,NC,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&page=$2 [L,QSA] 规则:

<div ng-repeat="note in ctrl.notes1">
        <span class="ng-cloak">{{note.$$hashKey}}</span>
        <span class="label" ng-bind="note.label"></span>
        <span class="author" ng-bind="note.done"></span>
</div>

在测试之前不要忘记清除浏览器缓存。