I currently have /a1234 (any number after letter "a") rewriting to page.php?var=1234, I have 1 particular page with number 55 I need to redirect elswehere.
rewriterule ^a55 /home/public_html/otherpage.php
While this simple line works, it also redirects /a555, /a5555 etc... to otherpage.php
- How do I only have it redirect just 55 and not 555 etc. ?
CodePudding user response:
rewriterule ^a55 /home/public_html/otherpage.php
This matches any URL-path that simply starts a55
. The ^
is a start-of-string anchor. You also need an end-of-string anchor ($
) to match just that URL-path. For example:
RewriteRule ^a55$ /home/public_html/otherpage.php [L]
You should also include the L
flag, to prevent further processing. And this rule must go before your more general rule.
Reference:
CodePudding user response:
With your shown samples, please try following htaccess rules file. Make sure to clear your browser cache before testing your URLs.
Make sure your new rule is places above old rule.
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]