Apache 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
我想将网址转换为:
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]
答案 0 :(得分:3)
在.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成为函数参数。
答案 1 :(得分:0)
尝试:
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]