我有一个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/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]
并在应用程序 – >配置 – > routes.php添加这样的路线
$route['country/(:any)/(:any)/(:any)/(:any)'] = 'ControllerName/functionName/$1/$2/$3';
将“ControllerName”和“functionName”替换为您的实际名称。 $ 1,$ 2和$ 3成为函数参数。
有关详细信息CodeIgniter URI路由
试试:
Options -Indexes RewriteEngine on RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php/$3/index/$1/$2 [NC,L] RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php/$3/$4/$1/$2 [NC,L] RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php/$3/$4/$5/$1/$2 [NC,L]