.htaccess重写规则问题

时间:2014-01-06 14:01:28

标签: apache .htaccess mod-rewrite codeigniter-2 codeigniter-url

我正在尝试使用mod_rewrite重写一些网址。

我想重写

localhost/exotica/pet/somePet/

`localhost/exotica/index.php/types/get/somePet/`

我已设法使用

删除index.php
RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /exotica/index.php/$1 [L]

所以现在localhost/exotica/types/get/somePet有效 我试过添加第一条规则

RewriteRule ^pet/([A-Za-z0-9-]+)/?$ type/get/$1 [N]

但它根本没有用,所以请帮助我,我不知道如何启用它

我设法通过添加路由$route['pet/(:any)'] = "type/get/$1";来解决它,但我更愿意使用.htacess文件

1 个答案:

答案 0 :(得分:0)

按相反的顺序尝试这样的规则:

RewriteEngine On
RewriteBase /exotica/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pet/([A-Za-z0-9-]+)/?$ types/get/$1 [L]

RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]