I am trying to do a simple Apache
Redirect
that redirects a single page to a new URL, but not the child pages. E.g.
Redirect www.mysite.com/old to www.mysite.com/new
I do NOT want to redirect www.mysite.com/old/page1 to www.mysite.com/new/page1 or any childpages of /old.
Using a redirect like the following DOES include child pages:
Redirect 302 /old /new
How can I only redirect the top/parent page but not the child pages?
2
Answers
This is what I was looking for:
Use
RewriteCond
andRewriteRule
, like so:This way you verify that the requested URI is “/old”, and nothing else.
^/old$
:^
starts with$
ends withR=302
: you can put another status if you want, like 301L
: last rewrite to verify, do not apply further rewritesIf you try
http://www.example.com/old/somepage.html
, it will not match theRewriteCond
since it does not match^/old$
and will not redirect.