Jump to content

Module Url Short With Htaccess


Recommended Posts

Hi!

 

I am trying some time already short one module URL

 

From this

/module/csblog/

to simply

/blog/

 

I tried several thing in the .htaccess

 

Module uses own link create

so modify of the module is also possible

 

I hope many people tried same thing. 

public function createLinkPostDetail($module, $controller = 'default', array $params = array(), $ssl = false, $id_lang = null)
	{
		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/{module}{/:controller}/{id_cs_blog_post}-{category_parent}-{rewrite}.html', null, 1, 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]*'),
			), 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);
	}
	public function getLinkPostDetail($id_pl_blog_post, $link_rewrite, $category_parent)
	{
		$params = array();
		$params['id_cs_blog_post'] = $id_pl_blog_post;
		$params['rewrite'] = $link_rewrite;
		$params['category_parent'] = $category_parent;
		$url = $this->createLinkPostDetail('csblog', 'post', $params);
		return $url;
	}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...