URL重定向没有扩展名和斜杠结束 [英] Redirect urls without extension and slash at the end

查看:328
本文介绍了URL重定向没有扩展名和斜杠结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向所有的URL不带扩展名(www.mydomain.com/test)到我的主页,除了那些它与斜线(www.mydomain.com/test/)。

I would like to redirect all URL's without extension ( www.mydomain.com/test ) to my homepage EXCEPT the ones which ends with slash ( www.mydomain.com/test/ ).

下面code是伟大的工作......

The following code is working great...

RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+)$ http://www.mydomain.com [NC,R=301,L]

...但它也重定向的URL这与斜线结束。

... but it also redirects the URL's which end with slash.

如何才能做到这一点的网址与斜线在最后不被重定向?

How can I achieve that urls with slash at the end are not redirected?

感谢

推荐答案

我相信这将做你问什么,你只需要限制你的比赛不以斜线结尾的页面:

I believe this will do what you're asking, you simply need to restrict your match to pages which do not end with a trailing slash:

RewriteRule    ^(.+[^/])$           http://www.mydomain.com  [R]

不过,这听起来像是从物流的角度来看一个非常糟糕的主意。但我想这不是我的地方告诉你这一点,所以我会认为你有一个很好的理由这样做。祝你好运!

However, this sounds like a Really Bad Idea from a logistic standpoint. But I guess it's not my place to tell you that, so I'll assume you have a good reason to do this. Good luck!

这篇关于URL重定向没有扩展名和斜杠结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆