In my cakePHP v2.* I had a completely working application that does an ajax post to a file in /app/webroot/lib/upload/process.php
I now moved the site to a new server and get a missing controller error when I do the ajax post to the same file. So my first thought would be that somehow mod_rewrite wasn't configured... But the strangest thing is, when I access the file from my browser no error is shown. So only with the ajax call
BTW. I am running the site on an Ubuntu 14.04 server using ISPConfig as management console
The error I get is:
Missing Controller
Error: LibController could not be found.
Error: Create the class LibController below in file: app/Controller/LibController.php
And the ajax script is:
$('#my-upload-form').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
Where the form is:
<form action="/lib/upload/process.php" method="post" enctype="multipart/form-data" id="my-upload-form">
Console:
Request URL:https://www.bukadoo.com/lib/upload/process.php
Request Method:POST
Status Code:404 Not Found
Remote Address:52.37.22.4:443
The .htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
The .htaccess in webroot folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Well in the end it was a server issue. After installing the application on a whole different server things were working fine.
After a long search I found out that I needed to set the settings in ISPConfig from Fast-CGI to Mod-PHP
Related
currently, deploy a Laravel 8 project on an azure server via apache2, inside /var/www/html/Project. I have placed all the files inside the public on the root of the project and edited the index.php file's autoload.php & app.php according to the project path, which works, and the welcome page on URL / display the page correctly.
when I click on the button to navigate to another page, which displays 404 but routes are exist and working on localhost.
when submitting a post via Axios that also doesn't works which shows 404, that works on localhost.
following is the .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm working on a mvc php project but i'm having trouble with the .htcaccess file.
I want to rout everything trough index.php. But when i type http://localhost/mvc/public/test.php it doens't redirect to index.php, it displays an error 404 and when i type http://localhost/mvc/public/index.php?url=test.php it works. Btw i'm really new to mvc and routing.
.htcaccess code:
<IfModule mod_rewrite.so>
Options -Multiviews
RewriteEngine On
RewriteBase /mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?url=$1 [QSA,L]
</IfModule>
Try this at last line:
RewriteRule ^(.+)$ /mvc/public/index.php?url=$1 [QSA,L]
I created a wordpress plugin for calculating costs. The form have only one input-field and a submit button. On submitting the form I'd like to create a ajax request. So, I call the /wp-admin/admin-ajax.php- Url ,but I get the forbidden-Error-Code 403. I thought the entries in the htaccess are wrong, but I get the same error after changing the file and restarting the server.
Do you have any idea what's going on here?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# admin-ajax.php & post.php skip/bypass rule
RewriteCond %{REQUEST_URI} (admin-ajax\.php|post\.php) [NC]
RewriteRule . - [S=2]
</IfModule>
# END WordPress
It gives 403 forbidden error if you didn't declare that ajax call is allowed.
//allow this particular AJAX function for logged in users
add_action('wp_ajax_myajax', 'myajax');
//allow this particular AJAX function for non-logged in users
add_action('wp_ajax_nopriv_myajax', 'myajax');
function myajax() {
//your code
}
what worked for me was to disable mod sec on the server!
My code works perfectly fine while I am using it on my local and I can get the user info with postman and I have no issues getting the access token from server or localhost but using the access token for retrieving data from my real server always returns { message: unauthenticated } with status 401
The reason I found out is that Apache Drops the Authorize Header ! I have tried to fix it with adding these to my .htaccess but they don't do any help
my Apache vr is 2.4.29
this is my .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Someone please help me with this... :(
It seems the important thing I didn't know was that in first: some shared hosting websites don't allow you to access or modify the apache config file, and second: in the config file its needed to change the AllowOverride from None to All
AllowOverride All
I switched from a WH4S shared host to a Dreamhosting VPS and everything is working just as it should have been.
I have a little problem with codeigniter and the default controller behavior.
My CI resides in a subdir on the development environment at localhost/web/new_info and the same path for production like 192.168.30.108/web/new_info.
Always when calling the url like
localhost/web/new_info/welcome
the page takes me to the server root, e.g. localhost/.
But I can call the "welcome" controller via:
localhost/web/new_info/
localhost/web/new_info/index.php/welcome
and I can call welcome's methods as well like
localhost/web/new_info/welcome/logout
There is another subdir in my controllers called settings and contains another welcome.php intself. I can access this controller directly without problems and the page stays there
localhost/web/new_info/settings/welcome
There is .htaccess and mod_rewrite set up according to
http://www.farinspace.com/codeigniter-htaccess-file/.
.htaccess
SetEnvIf Host 192.168.30.108$ CI_ENV=production
SetEnvIf Host localhost$ CI_ENV=development
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/new_info/
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
in config/development/config.php I have
...
$config['base_url'] = 'http://localhost/web/new_info/';
$config['index_page'] = '';
...
and generic routes
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Xampp and the real server running apache2 act the same way. Even after completely disabling mod_rewrite and calling the welcome controller redirects to server root.
Currently I am using CI 3.0.3 and tested with the latest 3.0.6 as well with the same behavior.
What I want is to call localhost/web/new_info/welcome and stay there..
Thank you!
Ok, found out by myself.. dumb copy paste of .htaccess.
Namely the line
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
has to be
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ /web/new_info/ [L,R=301]
in my case. The author of the htaccess file didn't mention it on his page.
But changing the htaccess file only did not help. I had to completely restart my session, otherwise changes were not applied. It's a bit unusual for me, I thought changes in this file were instant.
Nevertheless, it's fine now.