I have an endpoint that I need to rewrite semantically for various reasons. The problem is it is an API endpoint and carries POST data. If I use a 301 or 302, the redirect happens, but I lose all data associated. I have stripped my .htaccess file down to bare bones for testing and still can't get it working.

DirectoryIndex index.php index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # APIs
    RewriteCond %{REQUEST_URI} ^/api/add_product$ [NC]
    RewriteRule ^.*$ /index.php?ACT=20 [NE,L]

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/(.*) /$1$2 [R=302,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

I am posting the JSON to the URL https://www.mysite.com/api/add_product and would like that to hit https://www.mysite.com/index.php?ACT=20

I can hit the ACT URL's fine but when I try to redirect/rewrite, I get either No input file specified. or a 404.

What am I doing wrong here??

  • I tried 301, 302, and 307. It was my understanding that 307s were to allow the POST data, but no luck. ;)
    – W3bGuy
    May 5 '18 at 17:17
  • Is there some technical reason you can't use the ACT url as is? I can think of some work arounds but might seem like a lot more work...
    – jrothafer
    May 9 '18 at 1:01
  • Just to be able to add instructions that don't change when the addon is uninstalled/reinstalled. Also, I have another usage that will be called from several other sites. Remembering to go and update an unknown number of sites if I upgrade, debug, or uninstall/reinstall the addon in the host site, would be extremely problematic.
    – W3bGuy
    May 11 '18 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.