Php htaccess Url重写不起作用
我对Apache URL重写有问题, 当用户录制url时,我希望如下所示: 1:Php htaccess Url重写不起作用,php,apache,.htaccess,codeigniter,mod-rewrite,Php,Apache,.htaccess,Codeigniter,Mod Rewrite,我对Apache URL重写有问题, 当用户录制url时,我希望如下所示: 1:www.site.com/country/city/smthg 或2:www.site.com/country/city/smthg/fct 或3:www.site.com/country/city/smthg/fct/value 我想将url转换为以下内容: 1:www.site.com/index.php/smthg/index/country/city 2:www.site.com/index.php/smth
www.site.com/country/city/smthg
或2:www.site.com/country/city/smthg/fct
或3:www.site.com/country/city/smthg/fct/value
我想将url转换为以下内容:
1:www.site.com/index.php/smthg/index/country/city
2:www.site.com/index.php/smthg/fct/country/city
3:www.site.com/index.php/smthg/fct/value/country/city
我正在使用PHP Codeigniter框架
我尝试过这个,但不起作用:
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index\.php|assets/|robots\.txt)
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php/$3/$1/$2 [L]
RewriteCond $1 !^(index\.php|assets/|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
尝试:
在.htaccess中使用此选项:
RewriteEngine on
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
在application->config->routes.php中添加如下路由
$route['country/(:any)/(:any)/(:any)/(:any)'] = 'ControllerName/functionName/$1/$2/$3';
将“ControllerName”和“functionName”替换为您拥有的实际名称$1、$2和$3成为函数参数
详细信息对于我来说,国家和城市是变量,我有多个控制员这为我工作:
$route['(:any)/(:any)/(:any)]='$3/索引/$1/$2'$路线['(:any)/(:any)/(:any)/(:any)']='$3/$4/$1/$2'$路线['(:any)/(:any)/(:any)/(:any)/(:any)]='$3/$4/$5/$1/$2'代码>Thx^^我们可以使用任意数量的路由。我总是使用显式路由。如果我有3个名为a、b、c的控制器,并希望使用2个变量来命中索引函数;一个字符串和第二个整数。我将使用:$route['a/index/(:any)/(:num)]='a/index/$1/$2'$路由['b/index/(:any)/(:num)]='b/index/$1/$2'$路由['c/index/(:any)/(:num)]='c/index/$1/$2'代码>
$route['country/(:any)/(:any)/(:any)/(:any)'] = 'ControllerName/functionName/$1/$2/$3';