Welcome Guest, Not a member yet? Register   Sign In
CI 3 input post not working when removed index.php
#1

Hi, i made forms many times before in CI 2 and everything worked fine on local and remote server all the time.
On local machine everything work fine even with CI 3 but when i uploaded file on server, as soon as i removed the index.php by removing it from config file like this: $config['index_page'] = '';  and in the htaccess like this: RewriteRule ^(.*)$ index.php?/$1 [L]
suddently the form doesn't send any post data to the controller. If i don't remove the index.php from url everything works fine,
i guess could be something concerning the htaccess but i'm totally lost..

This is my htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
   
    RewriteCond %{HTTP_HOST} ^mysite\.com
    RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
   
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

Really hope someone could help..
Thanks in advance!
Reply
#2

Check your rewrite rules. Some are using ? after index.php and some aren't.
You're sure mod_rewrite is enabled on the host?
Reply
#3

Rewrite mod is ok!

I believe the trouble starts from here:
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

This rules says to rewrite mysite.com to www.mysite.com and the form_open() generate mysite.com/controller
(as i set up http://mysite.com as base_url() in config file)
that is converted to www.mysite.com from the htaccess rule above.

I believe that this is messing up a bit codeigniter flow..

It's just a thought and tomorrow i'll try it..

thanks anyway..
Reply
#4

That's what I mean... in the RewriteRule it doesn't have a question mark after index.php like the other RewriteRule further down does. They should both be the same, whichever way works for your system but they shouldn't be different
Reply
#5

Also, if you are forcing non-www to www, your base_url should contain the www version.
Reply
#6

R=301 means an external redirect, that is requested by the server via a 301 status code ...

When that happens with a POST request, the client (browser) should ask you before making the redirect, but most (if not all) browsers will automatically do it and change it to a GET request.

There may be other issues with your rewrite rules, but this one is surely a problem - don't ever make an external redirect unless you want to redirect the client to a completely different site.
Reply
#7

Hi guys, i'll check everything you say.
Do you you think should i keep on forcing www. or the domain without www is just fine even for SEO?
Thanks
Reply
#8

Make sure your base_url and your rewrite rules agree on what your base URL should be, or you'll have problems with both SEO and your site's proper operation. If you're going to force www, you should never post a URL for your site which does not include the www. The rewrite rule in that case is about handling requests from other sites, not requests generated by your own site.

Also, if you ever plan to allow HTTPS for your site, it is usually best to include
Code:
RewriteCond %{HTTPS} !=on
as the first condition on any rule which includes http:// in the RewriteRule statement.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB