简体   繁体   English

mod_rewrite:URL字符串的重定向规则

[英]mod_rewrite: redirect rule for a URL string

I'm totally lost when it comes to mod_rewrite and redirect rules and was wondering if anyone could help!!! 当我谈到mod_rewrite和重定向规则时,我完全迷失了,想知道是否有人可以帮助!

I need a rewrite rule that will strip off a specific 14 character alpha numeric string from the end of the URLs ie domain.com/blahblah/z1234567891011 (the string always starts with the same letter, then is followed by 13 numbers). 我需要一个重写规则,该规则将从URL的末尾(即domain.com/blahblah/z1234567891011)中删除特定的14个字符的字母数字字符串(该字符串始终以相同的字母开头,然后是13个数字)。

I also need a rewrite condition so the rule is only applied to urls that contain the string, as not all of the urls on the site have the same string. 我还需要一个重写条件,因此该规则仅适用于包含字符串的url,因为并非网站上的所有url都具有相同的字符串。

Have spent quite a bit of time looking around at similar questions and testing on a simulator, but not finding anything that works so far. 花了很多时间在类似问题上并在模拟器上进行测试,但是到目前为止还没有找到任何可行的方法。

Thanks in advance! 提前致谢!

You can use in your .htaccess : 您可以在.htaccess使用:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+/)z\d{13}/?$ $1 [NC,R,L]

Or if you also strip off the new final / : 或者,如果您还删除了新的final /

RewriteRule ^(.+)/z\d{13}/?$ $1 [NC,R,L]

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

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