所以我最近一直在尝试使用.htaccess和URL重写,直到最近才一直运行良好。
基本上我将所有URL重定向到index.php,然后处理URL并显示正确的内容。所以如果我输入http://www.example.com/blog/index.html
可以正常工作和显示。但是,如果我输入http://example.com/blog/
,我会收到404错误...下面我已经放了.htaccess代码和PHP代码以防万一。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\.html)$ index.php/$1/ [L]
和PHP:
if(($_SERVER['REQUEST_URI'] == '/') || ($_SERVER['REQUEST_URI'] == '/index.php') || ($_SERVER['REQUEST_URI'] == '/index.html'))
{
//Looks like we are accessing the root
$this->controller = $this->config['default'];
} else {
$this->uri = explode('/', str_replace('.html', '', $_SERVER['REQUEST_URI']));
$this->controller = $this->uri[1];
if(isset($this->uri[2]))
{
$this->action = $this->uri[2];
}
}
任何帮助将不胜感激,谢谢!
答案 0 :(得分:2)
你的.htaccess应该是这样的
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]