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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.