URL重定向没有扩展名和斜杠结束斜杠、扩展名、重定向、结束

2023-09-02 01:00:09 作者:╯、爱不言深

我想重定向所有的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!

 
精彩推荐
图片推荐