htaccess重定向冲突

时间:2017-10-27 08:53:25

标签: .htaccess redirect

我在htaccess中编写代码以在url中添加尾部斜杠,同时应用重定向。 我的代码是 -

#Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]

Redirect 301 /social-media-consultant http://example.com/seo-consultant/
Redirect 301 /uiux-developers http://example.com/graphics-designer/

现在,问题在于当我编写用于添加斜杠的代码时,重定向将停止工作。

1 个答案:

答案 0 :(得分:0)

  1. 更改规则的顺序
  2. 仅使用基于mod_rewrite的规则。
  3. 这样做:

    RewriteEngine On
    
    RewriteRule ^social-media-consultant$ http://example.com/seo-consultant/ [L,NC,NE,R=301]
    RewriteRule ^uiux-developers$ http://example.com/graphics-designer/ [L,NC,NE,R=301]
    
    #Add slashes
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^ http://example.com/%{REQUEST_URI}/ [L,R=301,NE]
    

    确保在测试此更改之前清除浏览器缓存。