htaccess rewrite or redirect

I need to redirect just this url: http://2017test.rotarypdx.org/programs to this one: http://2017test.rotarypdx.org/programs-page

This url: http://2017test.rotarypdx.org/programs is actually a wordpress category so there will be sub-categories with posts in it. Those sub-categories and their posts I need to still go to the correct urls such as http://2017test.rotarypdx.org/programs/youth-programs/

When I use the regular redirect of:
redirect 301 /programs http://2017test.rotarypdx.org/programs-page
the sub-category also redirects with programs-page in it leading to a 404.
LVL 14
DzynitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
This should do the job for standard HTTP.  If you allow HTTPS it may more complicated and you might need two rulesets.

RewriteCond %{REQUEST_URI} ^/2017test.rotarypdx.org/programs$               [NC,OR]
RewriteCond %{REQUEST_URI} ^/2017test.rotarypdx.org/programs/$              [NC,OR]
RewriteCond %{REQUEST_URI} ^/2017test.rotarypdx.org/programs/index.html$    [NC]
RewriteRule .* /2017test.rotarypdx.org/programs-page/index.html             [L]

Open in new window


If your default page for unterminated URLs or URLs terminated in "/" is not "index.html", adjust the above as necessary.

NB:  The above uses mod_rewrite syntax for Apache 1 through Apache 2.2.  Apache 2.4 uses different syntax so this ruleset may not work on a 2.4 server.  In that case make the necessary adjustments.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You're seeing a 404 because the link you provided is a 404...

imac> curl -s -I -L http://2017test.rotarypdx.org/programs/youth-programs | egrep -ie ^http -e ^location
HTTP/1.1 301 Moved Permanently
Location: http://2017test.rotarypdx.org/programs-page/youth-programs
HTTP/1.1 404 Not Found

Open in new window


First start with a working link.

Also, I'd strongly suggest you use 302s until your entire rewrite strategy is working, else you may get a 301 stuck in your browser cache, which will make debugging very difficult.

The way I work out redirection problems for clients, is using curl, to avoid all browser caching issues.
0
DzynitAuthor Commented:
I couldn't get the rewrite to work so I just went a different route using the programs category description to display the page content and added some conditionals so posts from the sub-categories won't display when on http://2017test.rotarypdx.org/programs/
0
DzynitAuthor Commented:
Thank you for trying.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.