如果 url 不以 / 结尾,则将其重定向到 $1/
我想要的其实很简单。我基本上想做以下事情。
如果用户打开
http://www.mysite.com/somecategory/somedata
然后将用户重定向到
http://www.mysite.com/somecategory/somedata/
即添加一个
/at the end of the url.
我已经通过 .htaccess 解决了这个问题,但它仍然不起作用。这是代码
RewriteEngine on
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ http://localhost/thing
What i want is real simple. I basically want to do following.
If user opens up
http://www.mysite.com/somecategory/somedata
Then redirect the user to
http://www.mysite.com/somecategory/somedata/
i.e adding a
/
at the end of the url.
I've came to figured it out through the .htaccess, but still it is not working. Here's the code
RewriteEngine on
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ http://localhost/thing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将最后一行更改为:
应该可以。
编辑:您可能还应该添加第二个条件,以便不会重写对现有静态文件的请求(即
index.html
不会变成index.html /
):Changing the last line to:
should do it.
Edit: You should probably also add a second condition so that requests for existing static files are not rewritten (i.e.
index.html
doesn't turn intoindex.html/
):