简体   繁体   English

.htaccess mod_rewrite用于所有文件,包括文件名中的特定字符串

[英].htaccess mod_rewrite for all files including specific string in the filename

I have huge number of files that unfortunately are not longer needed. 我有大量的文件,很抱歉,不再需要这些文件。 But since some of them are already indexed by google, I would like to redirect traffic to another useful resource. 但由于其中一些已经被google索引,我想将流量重定向到另一个有用的资源。 (Using 301) (使用301)

File's names are constructed as per example 文件名按示例构造

xxxxxx-yyyyyy-zzzzzz-common-string.php XXXXXX-YYYYYY-ZZZZZZ-共string.php

So the regex will have to redirect all files that have string "-common-string" in common and php extension. 因此,正则表达式将必须重定向在common和php扩展中具有字符串“ -common-string”的所有文件。

I have no idea how to write RewriteCond and RewriteRule which would work in this case? 我不知道如何编写在这种情况下可以工作的RewriteCond和RewriteRule? Can you help please. 你能帮忙吗? Thank you 谢谢

只需在网站根目录.htaccess中使用以下一条规则,即可将所有此类URL重定向到您的首页:

RedirectMatch 301 -common-string\.php$ /

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

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