URL Suffix issue |
[eluser]Unknown[/eluser]
Hi all, Trying to set up codeigniter for the first time - don't seem to be able to use .html after I've removed the index.php using .htaccess. Here's .htaccess: RewriteEngine on # Makes .html not work!! RewriteCond $1 !^(index\.php|images|style|public|robots\.txt) RewriteRule ^(.*)$ /index.php?/$1 RewriteCond %{HTTP_HOST} ^www\.(.*) [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L] Here's my relevant config data: $config['index_page'] = ""; $config['uri_protocol'] = "AUTO"; $config['url_suffix'] = ".html"; Here's what works: http://mysite.com/index.php/test.html http://mysite.com/index.php/test http://mysite.com/test Here's what doesn't: http://mysite.com/test.html Any ideas?
[eluser]Unknown[/eluser]
So that I know - should i expect http://mysite.com/test.html to work with URL suffixes? Or am I just mistaken about how this should actually work?
[eluser]Daniel Walton[/eluser]
Just run into this too. Before I make a bug report I'm gonna dig around for a while and see if it's intended or not.
[eluser]Daniel Walton[/eluser]
Ok solved. If using htaccess to remove index.php (or whatever renamed variant) which I'm assuming you are also, then you are presumably using an .htaccess rule similar to: Code: RewriteCond %{REQUEST_FILENAME} !-f Please note the "?" in the rewrite rule, this is important. The core URI library has a function to retrieve the uri string from each incoming request called "_fetch_uri_string()". Within this function it uses a shortcut way of finding the uri string if the URL contains a "?" (remember our .htaccess?) If you can get away with it, i.e., if your server will support URL's like "http://example.com/index.php/controller", then just remove the question mark from your rewrite rule. If unfoprtunately your server setup can only understand "http://example.com/index.php?/controller" then you can either extend the core URI library to removes this conditional: Code: if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '') Or just comment it out. The other conditionals should catch the request. The reason this just doesnt work, for using url_suffixes on an index.php removed root url is that the $_GET key isn't allowed to contain periods, amongst other characters, so a request for "/foo.bar" is actioned as "/foo_bar" hence the 404. Hope this helps
[eluser]eangkasa[/eluser]
thanks daniel, without your post i wouldn't be able to figure out why that "?" in the rewrite rule has disabled the CI capability to load any page with .html extension. cheers, mate. |
Welcome Guest, Not a member yet? Register Sign In |