I try to redirect all my 404 error on my web site following those docs :
http://docs.joomla.org/Creating_a_Custom_404_Error_Page
So I edited my error.php :
<?php
defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
header('Location: http://www.mywebsite.com');
exit;
}
if { (!isset($this->error)) {
$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
$this->debug = false;
}
//get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;
?>
But when I clic on a link that should redirect me to a 404 error page - which should now redirect to my home page, it goes to the following link instead :
http://www.mywebsite.com/index.php?Itemid=359
How may I solve that problem ?
Joomla needs an itemID when building a page. My guess is that your default page is item ID 359. Joomla is appending that to the URL most likely because you do not have SEF URLs with rewrite turned on.
Correct code that you need (and more general) is:
if (($this->error->getCode()) == '404') {
header('Location: /index.php');
exit;
}
Some suggested the below, but I just want to redirect to main page not to an article:
if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=999');
exit;
}
Related
I am using EasyMDE text editor on my Notemaking website, but for some reason, the uploadImage functionality doesn't work.
This is how I instantiate EasyMDE.
var easyMDE = new EasyMDE({
autofocus: true,
autorefresh: true,
spellChecker: false,
minHeight: '180px',
uploadImage:true,
});
Can some one help me fix this issue or point me in the right direction of how to solve it?
I was searching for a PHP method but this is what I got :
https://github.com/Ionaru/easy-markdown-editor/pull/71
Edit:-
I figured it out in PHP
You need to also set the "imageUploadEndpoint" value to another file and save your image and print json.
This is how I did in PHP.
Client-Side:
var easyMDE = new EasyMDE({
uploadImage:true,
imageUploadEndpoint: 'upload.php'
});
Server-Side(in upload.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
header('Content-Type: application/json');
//logic for saving the file
if(image_saving_successful)
{
$url = the_filepath_for_the_image_saved
echo '{"data": {"filePath": "'.$url.'"}}';
http_response_code(200);
exit;
}else{
echo '{"error": "your_error_message"}';
http_response_code(400);
exit;
}
}else{
header('location: index.php');
exit;
}
?>
There are different response code for different error messages. Check Readme.md
Hello I am new in OpenCart and I am studying it now for my next project. And My first step in learning this framework? is to display my own page using a link from my navigation menu in admin area. But I am getting this error.
Notice: Error: Could not load template C:\wamp\www\myshop/admin/view/template/locations/countries_list.tpl! in C:\wamp\www\myshop\system\engine\controller.php on line 90
And I can't spot my error. Here's what I did.
Here's my controller /controller/locations/countries.php
<?php
class ControllerLocationsCountries extends Controller {
private $error = array();
public function index() {
$this->language->load('locations/countries');
$this->document->setTitle($this->language->get('heading_title'));
$this->getList();
}
protected function getList() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->template = 'locations/countries_list.tpl';
$this->response->setOutput($this->render());
}
}
Here's my simple view /view/template/locations/countries_list.php
<h1>Hello</h1>
Then in my header I include this code for displaying a link in menu navigation /controller/common/header.php
$this->data['text_locations'] = $this->language->get('text_locations');
....
$this->data['locations'] = $this->url->link('locations/countries', 'token=' . $this->session->data['token'], 'SSL');
That's all. I don't know what part is wrong. Can you help me with this?
The error is pretty self explanatory. The template file doesn't exist. Make sure the template filename and path is exactly the same and that you're using .tpl as the extension and not .php. It's also possible there could be a permissions error, but on WAMP that's not likely
I have paginated URLs that look like http://www.domain.com/tag/apple/page/1/
If a URL such as http://www.domain.com/tag/apple/page/*2/ doesn't exist, or page/2 doesn't exist, I need code to redirect this to a page such as http://www.domain.com/tag/apple/ which would be the main tag page.
I've currently have the following code:
RewriteCond %{HTTP_HOST} !^http://www.domain.com/tag/([0-9a-zA-Z]*)/page/([0-9]*)/$
RewriteRule (.*) http://www.domain.com/tag/$1/ [R=301,L]
In this code, if the URL does not exist it redirects to the main tag page, but its not working.
Does anybody have an hints or solutions on how to solve this problem?
If I understand what you're saying, you are saying that you have a list of rewritten URLs (using mod_rewrite); some of them exist, some of them don't. With the ones that don't exist, you want them to be redirected to a new page location?
The short-answer is, you can't do that within htaccess. When you're working with mod_rewrite, your rewritten page names are passed to a controller file that translates the rewritten URL to what page/content it's supposed to display.
I'm only assuming you're using PHP, and if so, most PHP frameworks (CakePHP, Drupal, LithiumPHP, etc.) can take care of this issue for you and handle custom redirects for non-existing files. If you have a custom-written application, you'll need to handle the redirect within the PHP website and not in the .htaccess file.
A very simple example of this would be:
<?php
function getTag($url) {
if (preg_match('|/tag/([0-9a-zA-Z]*)/|', $url, $match)) {
return $match[1];
}
return '';
}
function validateUrl($url) {
if (preg_match('|/tag/([0-9a-zA-Z]*)/page/([0-9]*)/|', $url, $match)) {
$tag = $match[1];
$page = $match[2];
$isValid = // your code that checks if it's a URL/page that exists
return $isValid;
}
return false;
}
if (!validateUrl($_SERVER['REQUEST_URI'])) {
$tag = getTag($_SERVER['REQUEST_URI']);
header ('HTTP/1.1 301 Moved Permanently');
header('Location /tag/' . $tag . '/');
die();
}
?>
I activated SEO friendly URLs. Basically URLs in my app looks like following:
http://x.com/en or http://x.com/en/gallery.
From my app there is no link, let's say, on com_users. But user still can open it with one of the following URLs: http://x.com/component/users or http://x.com/?option=com_banners.
I blocked first one with this:
RewriteCond %{REQUEST_URI} /component/ [NC]
RewriteRule ^.*$ - [F,L]
How can I block the second (?option=com_users)?
I understand that this behavior could be default and expected for Joomla, but I just want to give you one example.
When I allowed access to all my pages for only registered users they still are able to access components. At the same time in Joomla administration there is no permission for read. Finally, users are getting template page or some data if it is public, for ex., articles from com_content. And question: how to raise 403 in this case or, at least, redirect to / ?
Update:
I need to block /users?view=registration, reset remind and profile. And I need to redirect any error to login page. Doesn't matter whether it is whole Joomla component or view, task etc.
I would go another way, and use rel=canonical for this.
This is a much easier/better way of doing things, as the tag will appear on all "Page Versions" and you don't need to set many case-specific rules or carry around a heave redirect file...
This is just one Plugin that will help your canoniczlization.
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/meta-data/11038?qh=YTo0OntpOjA7czo5OiJjYW5vbmljYWwiO2k6MTtzOjExOiInY2Fub25pY2FsJyI7aToyO3M6MTI6IidjYW5vbmljYWwnLiI7aTozO3M6NToiY2Fub24iO30%3D
I wrote my own plugin to handle all cases and redirect to login page (/login) in case of any inconvenience. By inconvenience I mean any direct access to any component in Joomla, or 403, or 404, but not 500. For now, my application works very well accepting only following URLs: /login, /home, /gallery, /gallery/album/any, and few others. Direct access is totally forbidden, though, user cannot use URL params (like ?option=com_users) or /component/ path.
This approach wouldn't work with SEO URLs turned off.
<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.event.plugin' );
class plgSystemComontrol extends JPlugin {
function plgSystemComcontrol(& $subject, $config) {
parent::__construct($subject, $config);
}
function onAfterRoute() {
// get plugin parameters
$com_redirect_url = $this->params->def('com_redirect_url', 'index.php?option=com_user&view=login');
$com_debug = $this->params->def('com_debug', '0');
$com_message = $this->params->def('com_message', '');
// get option, view, task ..
$mainframe = JFactory::getApplication();
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$task = JRequest::getCmd('task');
// get current URL
$uri = JFactory::getURI();
$url = $uri->toString();
$u_host = $uri->getHost();
$u_path = $uri->getPath();
$path = substr($url, strlen(JURI::root()));
// get user permissions
$groupsUserIsIn = JAccess::getGroupsByUser(JFactory::getUser()->id);
$user_type = implode(" ",$groupsUserIsIn);
$group_sum = array_sum($groupsUserIsIn);
if ($com_debug == '1') {
$mainframe->enqueueMessage('--------------------------------');
$mainframe->enqueueMessage('$option = '.$option);
$mainframe->enqueueMessage('$view = '.$view);
$mainframe->enqueueMessage('$task = '.$task);
$mainframe->enqueueMessage('$url = '.$url);
$mainframe->enqueueMessage('$path = '.$path);
}
if (strpos($path, 'administrator') === 0) {
return;
}
// set default redirect page
$redirectPage = ($group_sum > 1) ? 'index.php' : 'index.php/login';
$directAccess = strpos($path, 'component') !== false || strpos($path, 'option') !== false;
// allow login page only
if ($option == 'com_users') {
if (($view == 'login' || empty($view) || $task == 'user.login' || $task == 'user.logout') && !$directAccess) { // $view == 'default'
return;
} else {
$mainframe->redirect($redirectPage, $directAccess ? 'Direct access to components forbidden' : 'Login/logout is enabled only');
//JError::raiseError(403, JText::_('Forbidden'));
//return;
}
}
// deny direct access to components
if ($directAccess) {
$mainframe->redirect($redirectPage, 'Direct access to components forbidden');
//JError::raiseError(401, JText::_('/component/'));
}
// get usertype to see if logged-in
// $user =& JFactory::getUser();
// $user_type = $user->get('usertype');
$groupsUserIsIn = JAccess::getGroupsByUser(JFactory::getUser()->id);
$user_type = implode(" ",$groupsUserIsIn);
$group_sum = array_sum($groupsUserIsIn);
if ($group_sum > '1') {
return ;
}
//if user logged-in, then return from function
if (empty($option)) {
return;
}
$mainframe->redirect( $com_redirect_url, $com_message );
return;
}
}
?>
I hope this will help to understand how to do some custom redirects and disable direct access to the components.
Its my first time to use web service in iOS.
REST was my first choice and I use code igniter to form it.
I have my Controller:
require APPPATH.'/libraries/REST_Controller.php';
class Sample extends REST_Controller
{
function example_get()
{
$this->load->helper('arh');
$this->load->model('users');
$users_array = array();
$users = $this->users->get_all_users();
foreach($users as $user){
$new_array = array(
'id'=>$user->id ,
'name'=>$user->name,
'age'=>$user->age,
);
array_push( $users_array, $new_array);
}
$data['users'] = $users_array;
if($data)
{
$this->response($data, 200);
}
}
function user_put()
{
$this->load->model('users');
$this->users->insertAUser();
$message = array('message' => 'ADDED!');
$this->response($message, 200);
}
}
, using my web browser, accessing the URL http://localhost:8888/restApi/index.php/sample/example/format/json really works fine and gives this output:
{"users":[{"id":"1","name":"Porcopio","age":"99"},{"id":"2","name":"Name1","age":"24"},{"id":"3","name":"Porcopio","age":"99"},{"id":"4","name":"Porcopio","age":"99"},{"id":"5","name":"Luna","age":"99"}]}
, this gives me a great output using RKRequest by RestKit in my app.
The problem goes with the put method. This URL :
http://localhost:8888/restApi/index.php/sample/user
always give me an error like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<xml>
<status/>
<error>Unknown method.</error>
This is my Users model
<?php
class Users extends CI_Model {
function __construct()
{
parent::__construct();
}
function get_all_users()
{
$this->load->database();
$query = $this->db->get('users');
return $query->result();
}
function insertAUser(){
$this->load->database();
$data = array('name'=> "Sample Name", 'age'=>"99");
$this->db->insert('users', $data);
}
}
?>
What is the work around for my _put method why am I not inserting anything?
Thanks all!
Unless you set the method to PUT or POST, your web server is not going to treat it as such. When you enter URLs in a browser bar, that is almost always a GET request. You might try to use curl like
curl -X POST -d #filename http://your.url.path/whatever
Another link would be: https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
So you should be able to do a PUT similarly (perhaps with no data). Not really sure if this should be iOS tagged though :)
I got this problem by using Firefox plug in rest Client.
I just have to indicate the headers and the body to make put and post work.