Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:11:56+00:00 2026-06-15T16:11:56+00:00

I’m creating an API, and I’m testing CRUD the functionality with an external client.

  • 0

I’m creating an API, and I’m testing CRUD the functionality with an external client.

To be able to skip index.php in the URL, and only use ‘…/producer/id’ etc I changed redirection in the .htaccess file (se below) which works accept for the fact that no other header code than 201 – Created can be sent out from the server. If I try to send out any other code it automatically becomes the following code:

HTTP/1.1 302 Found Date: Tue, 04 Dec 2012 19:42:10 GMT Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 X-Powered-By: PHP/5.3.1 Location: /producers/ Content-Length: 565 Content-Type: application/json

As an example is the php code below. If I add a ‘!’ before $result so that the statement becomes false the header in the else statement should be sent out, which doesn’t happen. Again, this 302 header is sent out. If I leave it as is the 201 header is sent out, just as it should.

Why is this happening?

php:

if ($result) {
    header('HTTP/1.1 201 Created');
        header('Location: /producers/' . $id);
}
else {
    header('HTTP/1.1 500 Internal Server Error');
    header('Location: /producers/' . $id
}

.htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine On

    # Allow images and statics to be addressable
    RewriteCond $1 !\.(gif|jpe?g|png|css|js)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # You have to manually change to our username or directory where our controller index is host

    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:11:58+00:00Added an answer on June 15, 2026 at 4:11 pm

    Location: always triggers a redirect, which is always a 3xx status code.

    If you want to output any other code, append it to the other header, and don’t send a Location:

    if ($result) {
        header('HTTP/1.1 201 Created', 201);
    } elseif ($errors) {
        header('Location: /theform.php'); // 301 by default
    } else {
        header('HTTP/1.1 500 Internal Server Error', 500);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.