htaccess重定向尾部斜杠

MZON

我正在尝试重定向网址,因此,如果该网址是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我在做什么错了?

贾斯汀·欧曼(Justin Iurman)

这应该工作

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]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

.htaccess:重定向尾部斜杠

使用Kirby的htaccess尾部斜杠重定向

.htaccess删除PHP扩展名与重定向尾部斜杠冲突

.htaccess > 将所有子文件夹重定向到根目录(忽略尾部斜杠)

没有尾部斜杠的django网址不会重定向

用于尾部斜杠的FastAPI重定向返回非SSL链接

重定向以某种方式添加了尾部斜杠

如何在 Symfony 4.1 中禁用尾部斜杠重定向?

htaccess尾部斜杠问题

htaccess重定向斜杠以获取参数

Nginx将http重定向到https并通过一个重定向删除尾部斜杠

如何仅将特定自定义帖子类型的URL从尾部斜杠重定向到非尾部斜杠?

htaccess重写删除尾部斜杠

在 Nginx 中重定向到新页面时如何删除尾部斜杠

无法禁用.NET Web Project中的尾部斜杠重定向

Apache 重写:如何自行检测和执行 301 尾部斜杠重定向?

Laravel 5分页带有尾部斜杠重定向到301

将尾部斜杠添加到url仅适用于非ww重定向

Node.js带有/不带有尾部斜杠的重定向

使用静态 HTML 并删除尾部斜杠时重定向次数过多的错误

将根目录重定向到子目录时,如何解决(缺少)尾部斜杠?

如何使用Nginx和PHP后端修复重定向到尾部的斜杠

发送POST请求:URL中缺少尾部斜杠会触发重定向GET请求

.htaccess重定向301:多个斜杠出现问题

重定向到index.php并删除斜杠.htaccess

htaccess重定向(如果网址末尾使用多斜杠)

重定向301 htaccess仅适用于斜杠Laravel

如果斜杠后没有任何内容,则htaccess重定向

如何在 .htaccess 中使用正斜杠重定向 url?