Forum Topic: Redirect noob question

Forum: .htaccess Forum : Redirecting • Posted by binalogue SL • Updated:

Hello

I’ve got a wordpress site and I wanted to add a shortcut as follows.

Redirect 301 /jobs/ http://www.example.com/about/jobs/

This works great.

The issue is now that I have a category called news, and for some reason all posts http://www.example.com/jobs/* are now also redirected to http://www.example.com/about/jobs/* which should only be the case if I was using RedirectMatch, correct?

So I’m wondering if there is a conflict, or if wordpress is doing something that I am not considering.

Also struggling with redirecting all subpages of a folder to its parentpage. So to speak a */foldername/**/foldername/

1 Reply to “Redirect noob question”

Posted by Jeff Starr

That is the correct functionality for Redirect, as explained in the Apache docs:

“The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.”

It then gives an example of Redirect:

Redirect /service http://foo2.example.com/service

..and goes on to say about this directive:

“If the client requests http://example.com/service/foo.txt, it will be told to access http://foo2.example.com/service/foo.txt instead.”

So in the case you’ve described, the posts are redirected as expected. To limit the redirect it’s possible to use RedirectMatch.

For the redirecting of all subpages to the parent directory, using mod_rewrite will help avoid recursive loops:

# place in root .htaccess
<IfModule mod_rewrite.c>
	RewriteCond %{REQUEST_URI} !/foldername/$ [NC]
	RewriteCond %{REQUEST_URI} /foldername/(.*) [NC]
	RewriteRule .* http://example.com/foldername/ [R=301,L]
</IfModule>

Test thoroughly, let me know how it goes!

Regards,

– Jeff