我正在尝试使用mod_rewrite重写一些网址。
我想重写
localhost/exotica/pet/somePet/
到
`localhost/exotica/index.php/types/get/somePet/`
我已设法使用
删除index.phpRewriteCond $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文件
答案 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]