htaccess的URL重写不工作 [英] htaccess Url rewriting not working

查看:114
本文介绍了htaccess的URL重写不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题与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

我要变换的网址是:

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框架,

我试过,但它不工作:

 选项-Indexes

RewriteEngine叙述上

的RewriteCond $ l ^(指数\ .PHP |资产/ |机器人\ .TXT)!

重写规则^([A-ZA-Z0-9  - ] +)/([A-ZA-Z0-9  - ] +)/([A-ZA-Z0-9  - ] +)$的index.php / $ 3 / $ 1 / $ 2 [L]

的RewriteCond $ l ^(指数\ .PHP |资产/ |机器人\ .TXT)!

重写规则^(。*)$的index.php / $ 1 [L]
 

解决方案

在.htaccess中使用这样的:

  RewriteEngine叙述上
重写规则^(应用|系统| \ .svn文件)的index.php / $ 1 [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [QSA,L]
 

和在应用程序 - > config-> routes.php文件添加这样的路线

  $航线['国家/(:任何)/(:任何)/(:任何)/(:任何)] ='ControllerName /函数名/ $ 1 / $ 2 / $ 3 ';
 

替换ControllerName和函数名与你的实际名称。 $ 1,$ 2和$ 3成为功能参数。

/ P>

I have a problem with the Apache URL rewriting, I want when the user tapes an url like this : 1 : www.site.com/country/city/smthg

or 2 : www.site.com/country/city/smthg/fct

or 3 : www.site.com/country/city/smthg/fct/value

I want to transform the url to this:

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

I am using PHP Codeigniter framework,

I tried this but it is not working :

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]

解决方案

Use this in .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]

and in application->config->routes.php add routes like this

$route['country/(:any)/(:any)/(:any)/(:any)'] = 'ControllerName/functionName/$1/$2/$3';

Replace 'ControllerName' and 'functionName' with the actual names you have. $1, $2 and $3 becomes function parameters.

For details CodeIgniter URI Routing

这篇关于htaccess的URL重写不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆