girish.kc Posted August 3, 2012 Share Posted August 3, 2012 Hi, Is there a way to modify the incoming URL request with rewrite? In my case, I have an external application calling mine with the URL https://api.xyz.com/folder I want this to be rewritten as https://api.xyz.com/folder/index.php I tried the following .htaccess to do that. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^folder$ /folder/index.php [L] </IfModule> But the problem here is, this is a POST request and because of rewrite server is sending back the '301 Moved Permanently' status back to the requester. Is there any way I can skip sending 301 and redirect without loosing the POST data? Thanks, Girish Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/ Share on other sites More sharing options...
requinix Posted August 4, 2012 Share Posted August 4, 2012 Get rid of the [L]. But are you sure you even need this? If /folder/ actually is a folder and you have index.php listed as a DirectoryIndex then Apache should do that rewriting automatically. Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1366704 Share on other sites More sharing options...
girish.kc Posted August 7, 2012 Author Share Posted August 7, 2012 Yes. I have the index.php in DirectoryIndex, But for the request "https://api.xyz.com/folder" I am getting the following response Date: Tue, 07 Aug 2012 05:43:55 GMT Server: Apache Location: https://api.xyz.com/folder/ Content-Length: 243 Keep-Alive: timeout=1, max=10000 Connection: Keep-Alive Content-Type: text/html; charset=iso-8859-1 Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367400 Share on other sites More sharing options...
requinix Posted August 7, 2012 Share Posted August 7, 2012 Yeah... that's DirectorySlash kicking in. Mostly harmless. Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367402 Share on other sites More sharing options...
girish.kc Posted August 7, 2012 Author Share Posted August 7, 2012 No.. It is creating the problem. When a POST request is sent, this 301 will redirect the request and the POST request becomes GET. So the POST value will be lost.. Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367479 Share on other sites More sharing options...
Christian F. Posted August 7, 2012 Share Posted August 7, 2012 Get rid of the [L]. Did you do this? Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367502 Share on other sites More sharing options...
requinix Posted August 7, 2012 Share Posted August 7, 2012 Disabling DirectorySlash is a bad idea. Can't you just change the form to point to the right place? Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367606 Share on other sites More sharing options...
girish.kc Posted August 8, 2012 Author Share Posted August 8, 2012 Yes . I tried without [L]. Same result. Quote Link to comment https://forums.phpfreaks.com/topic/266655-rewrite-url/#findComment-1367730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.