htaccess的URL重写不工作重写、工作、htaccess、URL

2023-09-02 09:53:58 作者:大风大浪就是闯

我有一个问题与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 ';
 
PHP .htaccess 在自己电脑上运行正常上传到空间打不开

替换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