Currently I have this set up in my .httaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(php|html|txt|js|css|png|jpe?g|gif|svg|woff|ico|csv|xml|pdf|gzip)
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule (.*) /$1.php [L,R=301]

so basically I am redirecting all URLs that do not have any extensions to php pages.

for example I redirect /test to /test.php and I throw 301 while I do this.

What I would like to have is first throw 404 on /test and immediately after throw 301 and redirect to /test.php.

Is it possible to write something either to .htaccess or in apache .conf files to achieve this?


first throw 404 on "/test" and immediately after throw 301 and redirect to "/test.php".

You can't do that - regardless of what method you use (.htaccess, Apache, PHP, etc.). This is not how HTTP works. (But I'm not sure why you want to do this - the content either doesn't exist, or it has moved, it can't be both.)

  1. Browser requests /test
  2. Server responds with 404. (Initial browser request ends here.)
  3. The "browser" would then need to make another request for the server to then respond with a 301. (The browser would also need to modify the request so the server knows not to send a 404, but to send a 301 instead.) - This is not going to happen.

For any single request, you get a single response - one status code.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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