【问题标题】:htaccess redirect trailing slashhtaccess 重定向尾部斜杠
【发布时间】:2014-05-22 08:49:08
【问题描述】:

我正在尝试重定向 url,所以如果 url 是 http://foobar.com/admin/bla 将被重定向到 http://foobar.com/admin/bla/

这是.htaccess文件的内容

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|assets|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]

问题是重定向不起作用。当我输入 http://foobar.com/admin/bla 时,响应为 200。 我想要的是 301 重定向到带有 / 结尾的 url 我做错了什么?

【问题讨论】:

  • [L,R=301] 应该是[R=301]
  • 我改成[R=301]但是没有效果

标签: apache .htaccess codeigniter redirect


【解决方案1】:

这应该可以代替

RewriteEngine on
RewriteBase /

# if it's an existing folder or file, do nothing
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]

# if no trailing slash then add it
RewriteRule ^(.+)([^/])$ $1$2/ [L,R=301]

# internally rewrite url to index.php controller
RewriteRule ^(.*)$ index.php/$1 [L]

【讨论】:

    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2019-03-28
    • 2013-05-10
    • 2017-09-28
    相关资源
    最近更新 更多