从 a55 而不是 a555、a5555 等重写
Rewrite from a55 but not a555, a5555 etc
我目前将 /a1234(字母“a”后的任何数字)重写为 page.php?var=1234,
我有 1 个编号为 55 的特定页面,我需要重定向到 elswehere。
rewriterule ^a55 /home/public_html/otherpage.php
虽然这个简单的行有效,但它还会将 /a555、/a5555 等重定向到其他page.php
- 我如何让它只重定向 55 而不是 555 等等?
使用您显示的示例,请尝试遵循 htaccess 规则文件。确保在测试您的 URL 之前清除您的浏览器缓存。
确保您的新规则高于旧规则。
RewriteEngine ON
##New Rule for a5, a55 etc here.
Rewriterule ^a5+$ /home/public_html/otherpage.php [QSA,NC,L]
##Your already existing rule for page.php file.
Rewriterule ^a[0-9]+$ /home/page.php?var=1234 [QSA,NC,L]
rewriterule ^a55 /home/public_html/otherpage.php
这匹配任何仅 starts a55
的 URL-path。 ^
是一个 start-of-string 锚点。您还需要一个 end-of-string 锚点 ($
) 来匹配 URL-path。例如:
RewriteRule ^a55$ /home/public_html/otherpage.php [L]
您还应该包括 L
标志,以防止进一步处理。这条规则必须 在 更通用的规则之前。
参考:
我目前将 /a1234(字母“a”后的任何数字)重写为 page.php?var=1234, 我有 1 个编号为 55 的特定页面,我需要重定向到 elswehere。
rewriterule ^a55 /home/public_html/otherpage.php
虽然这个简单的行有效,但它还会将 /a555、/a5555 等重定向到其他page.php
- 我如何让它只重定向 55 而不是 555 等等?
使用您显示的示例,请尝试遵循 htaccess 规则文件。确保在测试您的 URL 之前清除您的浏览器缓存。
确保您的新规则高于旧规则。
RewriteEngine ON
##New Rule for a5, a55 etc here.
Rewriterule ^a5+$ /home/public_html/otherpage.php [QSA,NC,L]
##Your already existing rule for page.php file.
Rewriterule ^a[0-9]+$ /home/page.php?var=1234 [QSA,NC,L]
rewriterule ^a55 /home/public_html/otherpage.php
这匹配任何仅 starts a55
的 URL-path。 ^
是一个 start-of-string 锚点。您还需要一个 end-of-string 锚点 ($
) 来匹配 URL-path。例如:
RewriteRule ^a55$ /home/public_html/otherpage.php [L]
您还应该包括 L
标志,以防止进一步处理。这条规则必须 在 更通用的规则之前。
参考: