我有一个 CodeIgniter 项目,需要重写规则来导航控制器/视图等。我已经在 Ubuntu 12.04 上正确安装了 hiphop-php,并且它运行良好,包括他们网站上提供的示例 WordPress 安装和重写规则。
但是,我需要找出适用于 CodeIgniter index.php/controller 设置的正确重写规则,而我自己的运气并不好。
这是一个用于 WP 重写的示例 hiphop-php 配置文件:
VirtualHost {
* {
Pattern = .*
RewriteRules {
dirindex {
pattern = ^/(.*)/$
to = $1/index.php
qsa = true
}
}
}
}
StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
这是 Apache 的示例 CodeIgniter mod_rewrite 文件:
http://www.farinspace.com/codeigniter-htaccess-file/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
基本上,我需要重写的只是使用 CodeIgniter 的 index.php 控制器正确路由请求,这似乎是 apache 重写规则的最后一部分所做的。其余的我可以在看到一些例子后一起破解。
非常感谢!