Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php URL的Yii模式匹配_Php_Yii_Url Rewriting_Custom Url - Fatal编程技术网

Php URL的Yii模式匹配

Php URL的Yii模式匹配,php,yii,url-rewriting,custom-url,Php,Yii,Url Rewriting,Custom Url,我需要在我的应用程序中处理一个SEO友好的URL。我的URL结构是:“domain.com/URL string/uniqueid”。例如: domain.com/properties-in-dubai/325fgd domain.com/properties-in-USA/4577ds6 domain.com/properties-in-india/567dew domain.com/apartments-in-anderi-mumbai/645fki 上面的URL字符串和ID由我们填充。当

我需要在我的应用程序中处理一个SEO友好的URL。我的URL结构是:“domain.com/URL string/uniqueid”。例如:

domain.com/properties-in-dubai/325fgd
domain.com/properties-in-USA/4577ds6
domain.com/properties-in-india/567dew
domain.com/apartments-in-anderi-mumbai/645fki
上面的URL字符串和ID由我们填充。当用户访问此URL时:

  • 首先需要验证URL模式
  • 第二步提取I'd和URL字符串,并与我的数据存储匹配
  • 第三,当上述URL和我存在于我们的数据存储中时,将引用的参数传递给现有的搜索页面

  • 请大家帮我解决这个问题,让我睡一觉。

    首先,您要在
    urlManager
    应用程序配置中添加一个新规则

    'rules' => array(
        '<slug>/<id:\d+>' => 'property/view'
        // ...
    )
    

    谢谢你的回答。但是当我使用重定向时,Seo友好的URL会发生变化。是否可以在重定向时维护相同的url
    class PropertyController extends CController
    {
        public function actionView($slug, $id)
        {
            $id = (int) $id;
    
            // Check if $id, $slug exist; replace line below
            $exists = true;
    
            if($exists){
                // Redirect to elsewhere
                $this->redirect();
            }
        }
    }