Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Right now I have a post type that generates a slug, e.g. http://url.com/l/abcd/ for each entry. I have a query in my 404.php that checks for http://url.com/abcd before output and redirects it if found in that post type "l"... What I'm wondering is, since 404.php will always send a 404 http header, is it not ok to do 301 inside 404.php (before any "output" starts)? It "works", but I suspect there is a better way...

Is it a bad idea to do a new rewrite_rule() for every slug in that post type? Is there a way to make post type "l" be top-level or checked "along with" page slugs?

share|improve this question
add comment

1 Answer

Sounds like you are doing it right. If you will add a rule per entry you will slow down the whole URL parsing, especially for pages.

About the 404. If you are actually redirecting, then it means that you don't send a 404 as there can be only one return code.

share|improve this answer
    
i actually just did some trial and error and noticed that wp already 301's url.com/abcd to url.com/l/abcd automatically, so i guess i will just put the final destination redirect in the single-l.php template file. also, i noticed that on another site that i did this sort of redirect on 404.php before get_header() and then i use a 404 header check (404checker.com) i get 404 Not Found even though the actual redirect occurs... so that is what prompted my question here. –  b747fp Feb 6 '13 at 7:43
    
That is strange, do you have an example to a page that both returns 404 and redirect? –  Mark Kaplun Feb 6 '13 at 7:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.