Slim framework 404 and rout erros - frameworks

I am writing an API with Slim Framework but I've been getting 404 error
require ('Slim/Slim/Slim.php');
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
$app->get('/', 'test'); // It is OK and I can see the return of my function "test" when I access domain/api
$app->get('/groups', 'getGroups'); // 404 error while I try to go to domain/api/groups
Someone know how to fix this route problem ?

It looks like a htaccess issue. That htaccess must be placed in your api folder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Related

codeigniter 3.1.9 with apache and php 7.2 - routing/redirect issues with symbolic links

SCENERIO:
Recently I migrated CodeIgniter from 2.4 to 3.1.9 along with PHP from 5.2 to 7.2. Also, created a new httpd.conf file in apache. When I go to the site's URL, it loads the default page fine and I can browse to default or root
pages without any issues. There are multiple sub-domains that are mapped in routes.php to the main httpd root directory /var/www/html. These sub-domains have a symbolic link to /var/www/html, and within assets folder are
the customization files for each sub-domains.
Root HTTPD directory "/var/www/html" structure
application assets
test1 -> /var/www/html
test2 -> /var/www/html
index.php
system
URL is set as follows in config.php.
$config['base_url'] = 'https://example.com/';
Below is my entry in routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";
Please check the below image for httpd directory config:
enter image description here
PROBLEM:
When I browse to https://example.com/ it loads everything correctly.
When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.
Not sure if this is caused by CodeIgniter URL routing issue or something to do with httpd.conf file of Apache. The same "routes.php" file was working fine on the old server.
The routing/pagination seems to have broken after I set $config['base_url'] = 'https://example.com/';. If left empty, it takes a while for the site to load, and when it does the forms and images are not loaded correctly.
I have spent lots of hours trying to figure out the problem. I am hoping someone genius out there will be able to show be in the right direction.
Thank you.
I had this problem when I upgraded to PHP 7.2, the best solution is ,
for things to work in CI with PHP7.2,
Find and comment out(or remove) the following code from sessions.php (system/libraries/session/session.php) and place it in your index.php at the top.
session_start();
ini_set('session.use_trans_sid', 0);
ini_set('session.use_strict_mode', 1);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character',4);
and for .htaccess, use this
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|.well-known|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1
set your uri protocol to AUTO
$config['uri_protocol'] = 'AUTO';
$config['index_page'] = '';

redirect 301 all categories links in wordpress + Redirection plugin

how to redirect all links:
http://www.babynames.ir/esm/oldcat/page1/number/...
to:
http://www.babynames.ir/esm/newcat/page1/number/...
oldcat -> newcat
im using:
Permalink-Finder AND 404 redirect but mess all link.
using Redirection plugin but could not set the parameters...
how about using htaccess like this
add to your .htaccess file after the RewriteEngine On
RedirectMatch 301 http://www.babynames.ir/esm/oldcat/(.*) http://www.babynames.ir/esm/newcat/$1
or may be like this
RewriteRule ^oldcat/?$ $1/newcat$2 [R=301,L]

Redirect root domain homepage to another domain subdirectory

I would like to:
Redirect www.olddomain.com to www.newdomain.com/page
Redirect www.olddomain.com/article1 to www.newdomain.com/article1
Here is what I put into my htaccess file:
redirect 301 / http://www.newdomain.com/page
redirect 301 /article1/ http://www.newdomain.com/article1
The first redirect works, however, the second one does NOT work, since www.olddomain.com/article1 redirects to www.newdomain.com/page/article1, which does not exist and thus returns a 404 error.
How to redirect the old domain home page (root) to a new domain subdirectory, without affecting all other redirects?
In .htaccess code should look like that:
RewriteEngine On
RewriteRule ^/$ http://www.newdomain.com/page [L,R=301]
RewriteRule ^/article1/$ http://www.newdomain.com/article1 [L,R=301]

Ez Publish Unable to get REST API working

I am new to Ez Publish, I would like to make the default Rest API working as a first step and next developing my own Rest API extension for mobile communication purpose but I am blocked at the first one.
when I try to get the result from "www.mydomain.com/api/ezp/content/node/2/list" I get "{"error_message":"Not Found"}"
configurations are done:
setting/override/site.ini.append.php
[ExtensionSettings]
ActiveExtensions[]
ActiveExtensions[]=ezprestapiprovider
...
extension/ezprestapiprovider/settings/rest.ini.append.php
<?php /* #?ini charset="utf-8"?
[ApiProvider]
ProviderClass[ezp]=ezpRestApiProvider
[Authentication]
RequireAuthentication=disabled
*/ ?>
.htaccess
DirectoryIndex index.php
RewriteEngine On
RewriteRule api index_rest.php [L]
RewriteRule ^index_rest\.php - [L]
...
I apologize for my English.
Edit1: Ez Publish version 4.5
Edit2: It seems to be a problem of RewirteRule, when I change "www.mydomain.com/api/ezp/content/node/2/list" to "www.mydomain.com/index_rest.php/api/ezp/content/node/2/list" it works , how can I fix that ?
Edit3:
I tried all rewriterules below, still not working except the last one.
# RewriteRule ^/api/ /index_rest.php [L]
# RewriteRule ^api/(.*) /index_rest.php/$1 [R=302,NC]
# RewriteRule ^/api/(.*) /index_rest.php/api/$1 [NC,L]
RewriteRule api index_rest.php [L]
But it seems to create conflit when I try to add new extension...
I added a new extension and when I try to access to it I got an error on the log file:
Unexpected error, the message was : The API provider 'mobile' could not be found. in mydomaine.com\kernel\private\rest\classes\rest_provider.php on line 37
Try replacing those rewriterules with the one specified by eZ
RewriteRule ^/api/ /index_rest\.php [L]
This is listed here for version 4.5: http://doc.ez.no/eZ-Publish/Technical-manual/4.5/Installation/Virtual-host-setup
I just regenerate autoload and it's working now. I use cmd line to do it (regenerating autoload with admin module does not work for me).

Help for htacess redirect rgex ( im use for redirecting web page to mobile device)

Dear ..
I doing some app for android and Iphone .. so i need to redirect web pages to the news mobile style web..
I got some htaccess code from internet but not work in my site cause of regex
sample: origin link:
http://www.xaluan.com/modules.php?name=News&file=article&sid=236233
mobi link:
http://www.xaluan.com/modules.php?name=News&file=article_mobi&sid=236233
here the htacess i'm working on
#Redirect if mobile device
RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-) [NC]
RewriteRule (.*)file=article&sid=([0-9]+)$ /modules.php?name=News&file=article_mobi&sid=$1 [R,L]
I'm trying to corect the RewriteRule but not work .. what im doing worng .. please corect
thanks
You can try adding the following to the .htaccess file before the rewrite rules.
Options +FollowSymlinks
RewriteEngine on