简体   繁体   English

htaccess重定向尾部斜杠

[英]htaccess redirect trailing slash

I'm trying to redirect url's so if the url is http://foobar.com/admin/bla to be redirected to http://foobar.com/admin/bla/ 我正在尝试重定向网址,因此,如果该网址是http://foobar.com/admin/bla要重定向到http://foobar.com/admin/bla/

Here is the content of .htaccess file 这是.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]

The problem is that the redirection doesn't work. 问题是重定向不起作用。 When I type http://foobar.com/admin/bla the response is 200. What I want is to be 301 redirected to the url with the / at the end What I'm doing wrong? 当我输入http://foobar.com/admin/bla时 ,响应为200。我想要的是将301重定向到/末尾的URL我在做什么错了?

This should work instead 这应该工作

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM