简体   繁体   English

仅当使用.htaccess以两个特定字符结尾的URL时,才如何捕获该URL?

[英]How to catch an URL only if it ends by two specific characters using .htaccess?

I need to catch URLs that end only by /s examples: 我需要捕获仅以/ s示例结尾的URL:

www.example.com/contact/s www.example.com/test/s www.example.com/contact/s www.example.com/test/s

All of them have to be redirected (301) to: 所有这些都必须重定向(301)到:

www.example.com/s www.example.com/s

But, if I have some page like www.example.com/system it should not be redirected, even it containing /s. 但是,如果我有一些类似www.example.com/system的页面,则即使包含/ s,也不应将其重定向。

Is it possible? 可能吗?

Try: 尝试:

RedirectMatch 301 ^/[^/]+/s$ /s

or 要么

RewriteEngine On
RewriteRule ^[^/]+/s$ /s [L,R=301]

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

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