I manage to disable the homepage on Prestashop.
I want that users arrive in a specific category and not on the homepage.
I've tried to do it in the htaccess file with a redirection of index.php to index.php?category_id=1.
It works but it generate the error Technical error unable to load form when the user try to create an account.
This applies to PrestaShop 1.5
You may edit controllers/front/IndexController.php file, which is responsible for the homepage, adding Tools::redirect call to whatever controller you want (this example is to cart).
public function initContent()
{
parent::initContent();
Tools::redirect('index.php?controller=cart'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
$this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome'));
$this->setTemplate(_PS_THEME_DIR_.'index.tpl');
}
Well for one way you can simply add a redirect to your index.php file, but that I guess is already evaluated and rejected solution:
header('index.php?category_id=1');
exit;
Another way of doing this might be using the prestashops modules, for example there is a module "homefeatured" which displays exactly the products for the home category and you can hook it on home position through Modules -> Positions.
If you would mind telling me the exact major version of prestashop you are using maybe I could tell something more.
Related
I want user to type any URL, example:
mywebsite.com/helloworld
After, with PHP i'd like to take slug helloworld, and print it on the page.
By default Wordpress shows 404 page. My idea was to disable this page, but not sure if there's a better solution.
How i can achieve that?
add_filter( 'pre_handle_404', function() {
# you can do anything you want here but the easiest and safest is
# wp_redirect( 'your url with query parameters from the failing 404 url' );
# exit();
return FALSE;
} );
404 is one of many HTTP Status Codes and as such if you completely remove the page, you'll need to both disable it in WordPress and on your web server, eg Apache or Nginx. This is not advised as it will make browsers display legitimate 404's with uncontrollable/undesirable responses.
If your question is "the default/my templates 404 page is terrible and I want to change it" refer to the Codex page on custom 404 page or use one of the numerous plugins designed to template error pages.
I would also, personally, advise against directing error pages to a page of your choosing, eg your homepage. This does very little except confuse people wondering why example.com/helloworld goes to example.com. From a programmers perspective, it could add time to your development as you may find it harder to diagnose why you're getting redirected to your homepage rather than it coming up with 404 or 500 which each tell you different information.
To go off of #magenta you can add conditions to this as well. This is what I did:
add_action( 'pre_handle_404', function() {
global $wp_query;
if(!$wp_query->found_posts){
if($wp_query->query['post_type']=="clients"){
wp_redirect( '/login' );
exit;
}
}
return FALSE;
} );
I have a problem with getting Joomla 3 to redirect users to a member page when a 403 is detected.
Upon researching and trying various things for literally days now I've finally given in to having to ask the question.
From my research I understand that the Joomla reads from the templates/system/error.php master file.
I have the following code implemented within the error.php and I have tried forcing it through .htaccess as well and neither work.
$ReferTo = $_SERVER['REQUEST_URI'];
$ReferTo = base64_encode($ReferTo);
if ($this->error->getCode() == '403') {
header('Location: ' . $this->baseurl . '/members'); die();
}
The current behaviour is Joomla just sends the user to a very unhelpful 403 default page.
Any ideas on this one? Thanks so much for any help.
Fortunately I have managed to find a solution by fluke. I dropped the system folder error.php file into all the individual template folders to create a system override. So far Joomla has recognised this.
Create under the main directory of your Joomla website, a 403.html file with the following content:
<meta http-equiv="refresh" content="0; url=http://www.yourwebsite.com/members" />
In your .htaccess file, add the following code:
ErrorDocument 403 /403.html
If you only want to do that for certain requests, then redirect to a 403.php file in your .htaccess file (instead of redirecting to 403.html file), check the REQUEST URI to see if it is indeed coming from the members area, and then redirect back to the members page.
Joomla creates/raises a 403 event, when trying to access a protected article. So editing the file System / error.php or within the template itself did not work. Also the other solutions in .htaccess or httpd.conf using ErrorDocument did not work.
I also tried the code this-> error-> getCode () == '403', but it doesn't fire.
The only solution I found was to modify the HTML view for the articles to redirect to an article where I show a login and a personalized message.
The file to modify is components / com_content / views / article / view.html.php line 134 to 139
Joomla 3.9.20
The code to replace is the following:
// Check the view access to the article (the model has already computed the values).
if ($ item-> params-> get ('access-view') == false && ($ item-> params-> get ('show_noauth', '0') == '0'))
{
$ app-> enqueueMessage (JText :: _ ('JERROR_ALERTNOAUTHOR'), 'error');
$ app-> setHeader ('status', 403, true);
return;
}
For this
// Check the view access to the article (the model has already computed the values).
if ($item->params->get('access-view') == false && ($item->params->get('show_noauth', '0') == '0'))
{
header('Location:https://www.yourwebpage/withLoginandCustomMessage.php');
die();
}
This will only be shown to users trying to view articles that require registration or with other ACLs.
I am aware that we should not edit the files since in a Joomla update, these changes could be lost, but it was the only solution I found (neither modules or plugins covered this problem and apparently it is something that is brought from joomla 1.5).
Problem
I have added a new catergory that has the urlkey of "shoes". This urlkey was found to be problematic as the URL redirect linked it to shoes-86. This was because there are several dozen disabled/legacy products with the same url key (shoes). Understanding that manually creating redirects would have adverse side effects. I was tasked to solve it programmatically using scripts and change all the urlkeys of the products so that magento can fix the redirects itself. This has created some problems.
Attempted solution
Currently i have this code which doesn't work, it does not create redirects. The following code is suppose to retrieve products with the url key of black_canvas_sneakers. It does this because it is my test product and I want to see the effects before applying the script to the whole database. This script only seems to retrieve products from the default store, no other stores for some odd reason. The problem i'm looking for the solution for is, why doesn't this code work and what can i do to make it work?
<?php
require 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore('0');
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('url_key', 'black-canvas-sneakers');
foreach ($collection as $product) {
$product->setData('save_rewrites_history', true)->save();
break;
}
I know the following code can make a redirect but senior magento developers have told me it could lead to unexpected side-effects. Thus this code is not best practice for creating permanent redirects.
/*Mage::getModel('core/url_rewrite')
->setIsSystem(0)
->setStoreId(2)
->setOptions('RP')
->setIdPath($product->getUrlKey() . '.html')
->setTargetPath($product->getUrlKey() . '.html')
->setRequestPath('shoes-' . $product->getId() . '.html' )
->save();*/
Manually altering url rewrite for default entities (like products and categories) might have adverse affects. The url indexer will recreate records that you may have deleted/changed.
You've described your solution, but not the problem you're trying to solve. Why are you creating redirects in the first place?
By default, when changing the url_key in the admin, there is an option to create a permanent redirect.
The same is true when updating the url_key programmatically
Mage::getModel('catalog/product')->load(905)
->setUrlKey('new-url-124')
->save();
We have a website based on Joomla! in the joomla directory, there are many other directories, i.e.:
C:\myjoomlawebsite
...joomla directories...
\myspecialdirectory
in "myspecialdirectory" there are resources that sometimes are available and other times are not available, as one would imagine, when a resource(php page) is not available, a 404 page is displayed.
What I would like to do is, "somehow" tell joomla that when the user tries to access a page located in "myspecialdirectory" and it's unavailable, it should show an article page rather than a 404.
if the user accesses mydomain.com/ <- all good
if the user accesses mydomain.com/existingpage.php <- all good
if the user accesses mydomain.com/unavailablepage.php <- a 404 should be shown
if the user accesses mydomain.com/myspecialdirectory/existingpage.php <- all good
if the user accesses mydomain.com/myspecialdirectory/unavilablepage.php <- here's where I want the user to see a article page in stead of a 404
Check this
For v1.5
if (($this->error->code) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}
For 1.6 & 1.7
if (($this->error->getCode()) == '404') {
Because that directory is outside of the Joomla framework, and you only want one directory to redirect to a Joomla page instead of a 404, then the easiest way to accomplish this is to use put a custom htaccess in the directory you want to redirect. You would want to add this to htaccess only in myspecialdirectory
ErrorDocument 404 /URL TO JOOMLA ARTICLE.php
For the standards-compliant solutions -- take a read here: http://magazine.joomla.org/component/k2/item/230
I have my wordpress blog at www.mysite.com , also I have my own php application at a subdomain l.mysite.com
I want the login credentials of WordPress in my PHP application. I figured out that by including the wp-blog-header.php from the root to my app.
I can use the user info OK.
I wanted to redirect users to www.mysite.com/wp-login.php?redirect_to=l.mysite.com . You can see here that I am specifying the redirect_to parameter. Wordpress ignores this and redirects to admin panel.
I think that worpdress doesn't allow redirect to an "external domain" , which I think is specified in wp_safe_redirect() function in wordpress. Is there any plugin which could ignore some domain to which redirect can happen?
I see that there are many login specific redirect plugins but none which could do to a new doamin.
Check this Plugin: http://www.theblog.ca/wplogin-redirect
Looks like it does what you want. Probably it's outdated, however, it should be trivial to create a plugin that fits your need.
A filter to start with is login_redirect, there is another filter in wp_safe_redirect() so you can prevent the domain you want to use being blocked.
To monitor redirects, checkout my Better HTTP Redirects Plugin.
+1 to #hakre . I don't have 15 rep so I can't upvote. Repost incase his
function cleanup_allowed_redirect_hosts( $hosts )
{
$allowed_hosts = array('first.domain.com', 'second.domain.com', 'etc.domain.com');
return array_merge( $hosts, $allowed_hosts );
}
add_filter( 'allowed_redirect_hosts', 'cleanup_allowed_redirect_hosts', 10, 1 );