Answer the question
In order to leave comments, you need to log in
How to remove slash after id text in url?
Hello.
I have a problem -
There is a link like this:
site/user/id/1
but I need it to look like this:
site/user/id1,
that is, remove the slash after the id.
Is it possible to somehow implement this using .htaccess?
Thanks!)
Answer the question
In order to leave comments, you need to log in
why make life difficult for yourself?
a link like /site/user/id/1 is more convenient
in general, it is better to do routing through php or in the language in which you process it,
make a single entry point through htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
$uri = explode('/',trim($_SERVER['REQUEST_URI'],'/'));
$parm1['page'] = $uri[0]; // site
$parm1['action'] = $uri[1];// user
$param1[$uri['2']] = $uri['3']; // ПОЛУЧАЕТСЯ id = 1
<?php
class router
{
use singleton, debugFn;
private $Route = array();
private $ControllerName = '';
private $ControllerObject = null;
private $ActionName = '';
private $Argument = array();
private function GetUrl()
{
$this->Route = RequestHttp::getRequestUri('array');
}
private function IssetDefault()
{
if($this->Route[0] == null)
{
$this->ControllerName = 'default';
$this->ActionName = 'index';
}else{
$this->GetNameController();
$this->GetNameAction();
$this->GetArguments();
}
}
private function GetNameController()
{
$this->ControllerName = array_shift($this->Route);
}
private function GetNameAction()
{
$this->ActionName = array_shift($this->Route);
}
private function GetArguments()
{
if(!empty($this->Route) && (count($this->Route) % 2 == 0))
{
for($i = 0; $i < count($this->Route); $i++)
{
$this->Argument[$this->Route[$i]] = $this->Route[++$i];
}
}
else
{
$this->ControllerName = 'default';
$this->ActionName = 'error404';
}
}
public function listen()
{
$this->GetUrl();
$this->IssetDefault();
DataRegistry::init()->set('arg',$this->Argument);
}
}
?>
if I'm not mistaken, you need to change the rule for generating the address (route) and not in .htaccess, but in the Yii
PS configuration, you can also use htaccess, but 1) this is a perversion (but there is any need) and Url::to() will still generate links like site/user/id/1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question