Shortening blog post address in browser - .htaccess

I need to shorten address in browser in PrestaShop from "csblog/post" to "blog". Customer is using blog plugin "CS Blog" which generates both links and addresses.
csblog is module, post is controller.
scheme of address is /csblog/post/friendly-name
Already tried changing link and address schemes in plugin files and found where exactly it's done, but after changing module and controller - it crushes. It can't find posts or no page error shows.
Already tried various .htaccess Rewrite sentences in main app (in folder and in main folder of module. No effects.
No help in internet as this plugin seems not very popular.
This is my current code in .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ csblog/post/([^&\]+)
RewriteRule ^blog/%1? [L]
How can I make this short address, should it be done with .htaccess or managed only via plugin?
Function that generates links:
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
$id_shop = Context::getContext()->shop->id;
$url = Context::getContext()->link->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);
$params['module'] = $module;
$params['controller'] = $controller ? $controller : 'default';
$dispatcher = Dispatcher::getInstance();
$dispatcher->addRoute('cs_blog_post', '{module}{/:controller}/{id_cs_blog_post}-{category_parent}-{rewrite}.html', null, 1, array(//{module}{/:controller}
'module' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'module'),
'controller' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'controller'),
'category_parent' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'category_parent'),
'id_cs_blog_post' => array('regexp' => '[0-9]+', 'param' => 'id_cs_blog_post'),
'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
), array('fc' => 'module',));
// If the module has its own route ... just use it !
if ($dispatcher->hasRoute('module-'.$module.'-'.$controller, $id_lang))
return Context::getContext()->link->getPageLink('module-'.$module.'-'.$controller, $ssl, $id_lang, $params);
else
return $url.$dispatcher->createUrl('cs_blog_post', $id_lang, $params);
}
Function that generates blog posts address:
public function hookModuleRoutes($params){
'cs_blog_post' => array(
'controller' => null,
'rule' => '{module}{/:controller}/{id_cs_blog_post}-{category_parent}-{rewrite}.html',
'keywords' => array(
'module' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'module'),
'controller' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'controller'),
'category_parent' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'category_parent'),
'id_cs_blog_post' => array('regexp' => '[0-9]+', 'param' => 'id_cs_blog_post'),
'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
),
'params' => array(
'fc' => 'module',
),
),
}

Routing is on your module's main file.
find function hookModuleRoutes on your file (probably csblog.php).
Then you can change your route

You might want to check on this expression to make sure if that would be the redirect you want to do. Then, you want to add a RewriteRul on your htaccess file. Maybe, something similar to this would work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} csblog\/post [NC]
RewriteRule ^(.*)csblog\/post$ $1blog [NE,R=301,L]
</IfModule>
Options -Indexes -MultiViews
Ever time that you change your htaccess, you may want to clear your browsing history and test it to see if it works.

Related

Laravel 4.2 application occurs unnecessary redirection after uploading live server

My laravel(4.2) application is working fine on localhost(xampp). But after uploading into live server when trying to login, it is showing a blank page with a message saying "redirecting to my home url". It also throws a login error
Sorry for my weak English. Please help me. I am attaching my htaccess below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Here is my Controller function.
public function adminLoginCheck() {
$validation_rule = array(
'username' => array('required', 'min:5', 'max:50'),
'password' => array('required', 'min:6', 'max:50')
);
$validation = Validator::make(Input::all(), $validation_rule);
// Validation Check
if ($validation->fails()) {
return Redirect::to('/')->withErrors($validation);
} // After Validation Authentication start
else {
$athentication = Auth::attempt(array('username' => Input :: get('username'), 'password' => Input :: get('password')));
// When Authentication True
if ($athentication) {
$rememberme = Input::get('remember');
if(!empty($rememberme)){
//Remember Login data
Auth::loginUsingId(Auth::user()->id,true);
}
//Redrict to the Target page
return Redirect::intended('adminDashboard');
} else {
//Redrict Login Form with Authentication error massege.
return Redirect::to('/')->with('authentication_error', 'Username or Password is not valid!');
}
}
}
My Auth filter is given below:
Route::filter('auth', function(){if (Auth::guest()){
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('login');
} } })
All of the blade templates are available.I am not understanding why the blank page is appearing with the redirecting message.Even when submitting login without inputting
username and password
Here is the live url http://noveltyshop.tech-novelty.com/
user:admin pass:pass
My route:
Route::get('/', array('as' => 'admin', 'uses' => 'UsersController#adminLoginForm'));
Route::post('/login', array('as' => 'login', 'uses' => 'UsersController#adminLoginCheck'));
Route::get('/adminDashboard', array('as' => 'adminDashboard', 'uses' => 'UsersController#adminDashboard'));
Route::get('/logout', array('as' => 'logout', 'uses' => 'UsersController#getLogOut'));
Route::get('/updateUserProfileForm', array('as' => 'updateUserProfileForm', 'uses' => 'UsersController#updateUserProfileForm'));
Route::post('/updateUserProfile', array('as' => 'updateUserProfile', 'uses' => 'UsersController#updateUserProfile'));
UsersController#adminDashboard
public function adminDashboard() {
return View::make('admin.pages.admin_dashboard')->with('title', 'AdminDashboard');
}
As you are using Laravel 4.2
You shall handle this in your Controller.
Here's the default way that we deal with
if (Auth::attempt(['email' => $email, 'password' => $password])) {
return Redirect::intended('yourTargetPageAfterLogin');
}
In the auth filter you shall have this
Route::filter('auth', function() {
if (Auth::guest()) {
return Redirect::guest('login');
}
});
Note : Make sure you have the blades as you defined in your Controller
Suggestion : Why not upgrade to 5.1 ?

installing 'EdpModuleLayouts' to zendframework 2

i am trying to install 'EdpModuleLayouts'
i have followed the instruction for the module here:
i also followed the issue here:
i. e; I placed the following code in my application.config.php?
return array(
'modules' => array(
... ,
'EdpModuleLayouts'
)
);
i then placed the following code in my module config
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
),
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),
i got the following error report:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException'
with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render
template "Workers/layout"; resolver could not resolve to a file' in
zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php
on line 499
The error message is so specific.
Unable to render template "Workers/layout"
This means that there is no template Workers/layout defined within the view_manager configuration. And the trick here is that you made a simple mistake of placing the configuration at the wrong place.
template_path_stack is used to give the view_manager information about some folders where template files are mapped going by their file-path.
template_map is used to give the view_manager information about which file covers a specific template.
The difference of the two can easily be seen when checking the module.config.php of the ZendSkeletonApplication. With this in mind, all you have to do is to change your configuration.
Another hint: don't CamelCase configuration keys, keep them lowercased ;)
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
),
'template_map' => array(
// consider to make this lowercase "workers/layout"
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
)
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),

how to set default theme in twig?

I use a silex with twig;
I create custom form_div_layout and put it in the webroot( for example)
I register TwigService provider like this
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/../views',
'twig.options' => array(
'cache' => __DIR__ . '/../cache/twig',
'strict_variables' => false
),
'twig.form.templates'=> [WEBROOT . '/form_div_layout.twig']
));
but i have an error
Twig_Error_Loader: Template "/home/versh/sale/web/form_div_layout.twig" is not defined () in "layout.twig" at line 52.
how to register theme correctly ?
I know that if i put theme in the twig.path it will work, but this is not solution
I'm using Twig with namespaces and I think it is the most flexible practice:
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array(
'cache' => true,
'strict_variables' => true,
'debug' => false,
'autoescape' => true
)
));
// set namespace for your application
$app['twig.loader.filesystem']->addPath(WHERE_EVER_YOU_WANT_PATH, 'yourApplication');
Now you can render templates using the namespace:
return $app['twig']->render('#yourApplication/sample.twig', array());
you can define as many namespaces as you need.
You have to add base template form_div_layout.html.twig to twig.form.templates option too.
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
'twig.options'=>array(
'cache' => __DIR__.'/../cache',
),
'twig.form.templates' => array(
'form_div_layout.html.twig',
'theme/form_div_layout.twig'
),
));

Using Silex Firewall in SecurityServiceProvider with {_locale}

When I configure Silex SecurityServiceProvider to work with {_locale} param, login.check_path returns a LogicException as follow:
LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
Following is my settings:
$app->register(new Silex\Provider\SecurityServiceProvider, [
'security.firewalls' => [
'login' => [
'pattern' => '^/{_locale}/login',
'security' => false,
],
'games' => [
'pattern' => '^/{_locale}/modules/',
'form' => [
'login_path' => '/{_locale}/login',
'check_path' => '/{_locale}/modules/login_check',
],
'logout' => [
'logout_path' => '/{_locale}/modules/logout',
],
...
],
...
],
]);
login_path and firewall handling seem to work fine, but can't finalize login process.
What's wrong with it?
I also ask you what's the correct route name of login_path, check_path and logout_path to serve to Twig {{ path() }} method, as I can't figure it out due to {_locale} presence.
Thank you.
Had the same problem today :) and found this solution:
add default_target_path and always_use_default_target_path to your security.firewalls form config.
'form' => array(
'login_path' => '/',
'check_path' => 'login_check',
'default_target_path' => '/' . $app['locale'],
'always_use_default_target_path' => true
),
Edit
So using $app['locale'] doesn't work well.
It's better you use $app['session']->get('locale') and set locale to session in a before middleware
$app->before(function (Request $request) use ($app) {
$app['session']->set('locale', $app['locale']);
....
});
Maybe somebody has a better solution by overloading event listeners. But I think this is a quick solution.

Pass arguments to a view in Drupal 6 via custom module

I'm using Drupal 6 to run a gallery I've created. I need to take a parameter from the AJAX request lets say "food" and pass that argument to a view I've created (Views 2) where "food" is a taxonomy term that I am using to get the data I want in return. Everything is working just fine and in my module's method for loading the view I can load the entire view because in the settings you have 'if no argument get all values', but I can't seem to pass arguments to it. Here is the method...
function ajax_methods_menu()
{
$items = array();
$items['admin/settings/ajax_methods'] = array(
'title' => t('AJAX Methods settings.'),
'description' => t('Define settings for the AJAX Methods'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_methods_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM
);
$items['gateway'] = array(
'title' => 'AJAX Gateway',
'page callback' => 'ajax_methods_get_items',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function ajax_methods_get_items($args)
{
$content = views_get_view('All_Images');
return drupal_json(array('status' => 0, 'data' => $content->preview('default')));
exit;
}
In looking at the documentation views_get_view() doesn't seem to allow for arguments although I believe they are being passed to my ajax_methods_get_items() method. Thanks for reading!
Got it figured out, I needed to add
return arg(1);
seems to be working pretty well.

Resources