我想重写代码的codeigniter网址重写。
我使用了以下代码。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/index.php?/$1 [L]
RewriteRue ^list/shows/cid-([0-9]+).html /list/shows?cid=$1注意:“test”是我的网站目录。
它可以很好地去除index.php。但是它不适用于url重写。
我想做http://example.com/test/list/shows?cid=1
成为
http://example.com/test/list/shows/cid-1.html
提前谢谢。
发布于 2012-09-18 15:52:21
为什么不使用框架中内置的routing capabilities呢?
您可以很容易地将这样的内容添加到application/config/routes.php中
$route['list/shows/cid-([0-9]+)'] = '/list/shows/$1';(我省略了.html部分,因为如果您将其设置为URL后缀,则不会将其考虑在内)
编辑:根据OP的第一条评论进行更新(在答案中移动了我的评论)
现在,所有的请求都被这个指令捕获:
RewriteRule ^(.*)$ /test/index.php?/$1 [L]尝试将您的自定义规则移到RewriteEngine On指令之后,更正您的RewriteRule拼写错误,并按照diEcho的建议向您的规则添加一个[L]。
发布于 2012-09-18 14:49:44
试一试
RewriteEngine on
RewriteBase /test
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/index.php/$1 [NC,L]
RewriteRule ^list/shows/cid-([0-9]+).html /list/shows?cid=$1 [NC]https://stackoverflow.com/questions/12471520
复制相似问题