0

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?

MrWhite
  • 11,643
  • 4
  • 25
  • 40

1 Answers1

0

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.

MrWhite
  • 11,643
  • 4
  • 25
  • 40