I've created a custom simple routing engine which works base on paths in 'PATH_INFO' in $_SERVER
. If the rout matches with any predefined routs, it will call its controller action; otherwise it will redirect to the home page.
$path = $_SERVER['PATH_INFO'];
if (in_array($path, $routs)) {
call_user_func(array($this, $action));// $action is calculated
}
else {
header('location: ./en');
exit();
}
In this case I modified the .htaccess file as below to hide the index.php and my urls be like http://www.example.com/en or http://www.example.com/en/home
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [QSA,L]
When I deployed sources to my domain by hitting url http://www.example.com redirects to http://www.example.com/en which is correct; but in response for that redirect it returns a 404 Page not found page!
Everything works fine in my machine localhost but on the web it does not work. The only different on my machine is that in .htaccess RewriteBase is set to my project path as RewriteBase /myrouting/
.
If I go to http://www.example.com/index.php/en on the web it works fine; but I don't want the index.php be visible.
UPDATE
I changed my .htaccess as below; now if I hit www.example.com/index.php/en it redirects to www.example.com/en but still with 404 error
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^index\.php)^(.+)$ /index.php/$1 [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(/[^\s\?]+)? [NC]
RewriteRule ^ %1%2 [R=302,L]
I will be thankful if anybody could help me what I've done wrong. I did search and tried different changes on .htaccess with no success.