Reputation: 705
So I have been dabbling with .htaccess and URL rewriting recently and it has been working well until recently.
Basically I redirect all URL's to index.php which then processes the URL and displays the right content. so if I enter http://www.example.com/blog/index.html
that works and displays properly. But if I enter http://example.com/blog/
I get a 404 error... Below I have put both the .htaccess code and the PHP code just in case.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\.html)$ index.php/$1/ [L]
and the 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];
}
}
Any help would be appreciated, thanks!
Upvotes: 0
Views: 185
Reputation: 6431
Your .htaccess should look like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]
Upvotes: 2