I converted the Codeigniter 3 advanced image library to Codeigniter 4 but the Route is not working
Codeigniter 3 route = $route['public/image/(:any)'] = 'media/resize/$1';
Codeigniter 4 route = $routes->get('public/image/(:any)', 'Media::resize/$1');
what is the point?
Solved
Change htaccess:
RewriteCond $1 !^(index.php|public|robots.txt|ads.txt|images|stylesheets|scripts|robots.txt)
to
RewriteCond $1 !^(index.php|robots.txt|ads.txt|images|stylesheets|scripts|robots.txt)
Related
When i write below code in route file it work perfectly but my "admin panel" redirect on frontend page(frontend/login/process link)(not show).
When i comment this, admin panel / frontend both working perfectly but not show this list page.
$route['(:any)'] = "frontend/home/productlist/$1";
I have used others in route file. Is there any issue let me know please.
$route['process'] = "frontend/login/process";
$route['admin']="admin/login";
$route['admin/product/(:num)'] = 'admin/product/index/$1';
$route['(:any)'] = "frontend/home/productlist/$1";
use like this :
$route['/(:any)'] = "frontend/home/productlist/$1";
I'm using Joomla v3.2
In the com_tags component I have modified the helpers/route.php file in order to include the catid and the Itemid in the url query. (The query is constructed by the module mod_easycloud which has been modified also).
$link = 'index.php?option=com_tags&view=tag&id=' .$id.'&Itemid='.JRequest::getInt('Itemid');
$link .= '&catId='.JRequest::getInt('catId');
I also modified the router.php file in order to build and parse the correct SEF url.
But when I'm switching to SEF urls, the Itemid parameter does not work. The content is correctly linked with the category catid, but the current menu item is not active.
The functionality above is working when I switch back to non-sef urls.
Try using JRoute::_( $link ).
This prepares the route to be used as a normal url and as a SEF url afaik.
im trying to redirect traffic i get from reddit to an article, but the image in the article is being hot-linked on reddit.com
this is fine but im wondering if theres a way that when users click on the image on reddit.com with a path like:
http://mysite.com/i/12345.jpg to redirect to http://mysite.com/r/12345
the only site I've noticed to do this successfully is livememe.com which has an image on reddit redirect to the article when clicked on. for example:
http://www.livememe.com/36opcf5.jpg redirects to http://www.livememe.com/36opcf5
and im trying to do something similar. Ive noticed that this redirect occurs whenever you go directly to that url.
Try this code :
RewriteEngine On
RewriteRule ^i/([a-zA-Z0-9]+)\.(jpe?g|JPE?G)$ /r/$1 [R=301]
I know it's been a few months since you asked, but if you still need a solution, I found an answer. Tried to find how it is done for a few hours, but unsuccessfully, so I had to come up with my own solution. Livememe doesn't do that redirect with htaccess, they do it with PHP. Since you can't see the difference in referrer, it would be the same whether the picture is embedded, or user clicks a link to it, you have to check something else. And the only difference I see is HTTP_ACCEPT header. If a resource is used as an image, it won't send HTTP_ACCEPT with a value of "text/html", it will be "image/jpeg" or something like that. So what you do is something like this: first, create .htaccess file with this:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /redirect.php?q=$1 [L]
So if a file is not found, redrect.php is loaded (wile your URL stays the same). And inside redirect.php put something like this:
$accept = explode(',', $_SERVER['HTTP_ACCEPT']);
$file = $_GET['q'];
$file_info = pathinfo( $file );
$url = $file_info['filename'];
$ext = $file_info['extension'];
$check_html = array_search('text/html', $accept);
if ( file_exists("$url.html") ) {
if ($check_html !== FALSE) header("location: http://yourdmain.com/$url"); // location of URL you want to redirect to
else header("location: http://i.yourdomain.com/$url.$ext"); // loction of image file
}
else {
header('HTTP/1.0 404 Not Found');
print 'File not found';
}
Adjust according to your server (the file_exists() part). Or you can check the database, to see that such post exists. Well, I think you get the idea, how that is done. Hope that helps.
I have a question and apologies if it is too simple but I really couldn't figure it out. If I have my domain for example: www.shop.com. I changed .htaccess to omit the need for index.php. Now I am wondering how can I load for example a page (main home page) without having any controller in url address. E.g.:
www.shop.com =========> should land me on the home page of my site.
currently the only way I can do it is by defining a controller and doing this:
www.shop.com/controller/
Thanks and your help is much appreciated :)
Go to /application/config/routes.php
Add the default_controller rule like so
$route['default_controller'] = 'home';
So now in /application/controllers/home.php method index() will run on the index page.
So right now I have this in my .htaccess page:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|js|fonts|css|robots\.txt)
RewriteRule ^(.+)$ index.php?$1 [L]
which makes it so that I can access http://www.yourdomain.com/index.php/page by going to http://www.yourdomain.com/page. However what I can't figure out is how to edit the page that shows up at http://www.yourdomain.com.
I've tried creating a controller called index, but this doesn't do anything unless you go to http://www.yourdomain.com/index
Can anyone help with this? Thank you!!!
The default controller that loads when there are no url segments is defined in application/config/routes.php:
From: http://codeigniter.com/user_guide/general/routing.html
Reserved Routes
$route['default_controller'] = 'welcome';
This route indicates which controller class should be loaded if the
URI contains no data, which will be the case when people load your
root URL. In the above example, the "welcome" class would be loaded.
You are encouraged to always have a default route otherwise a 404 page
will appear by default.
If there are no url segments besides the controller itself, by default the index() method of that controller is called (this is always the case, not just in regards to routing). So with this example you would look at the welcome controller and index method and see which view files etc. are being loaded.