I\'m running a LAMP environment with CodeIgniter. I want to be able to use its URL pattern, like, http://localhost/controller/function/ID
, but by default it has
Tried the answer here but that didn't work for me. So i tried the following and it did...
create the .htaccess in the root directory where the index.php along with license.txt is available. enter the following code in the file and store it:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
done! try it and it will surely work. Hope it helps
I had the same issues with CodeIgnitor links images,js,css. It all works now thanks to you guys! I have followed the below steps. consolidated all other comments into my scenario to work. Hope this helps somebody.
changed httpd.conf
<Directory --your root dir-- />
AllowOverride All #was "none", but this was all commented out
Order Deny,Allow
Deny from all
</Directory>
created an empty .htaccess file in the htdocs\yoursite(site root) directory and pasted the following.
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
This particular .htaccess file looks like it needs to go in your site's root (meaning, the currently executing site.)
Look into the documentation for RewriteCond to learn about what other kinds of conditions you can specify. Basically a RewriteRule
will only be applied if all of its preceding RewriteCond
s are matched. You could try adding these rules to only redirect if the requested URL does not exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
mod_rewrite is very powerful, but it can be a real pain if it's not doing what you think it should. I don't know of any way to debug its directives, either.
As far as what else you can do with a .htaccess file, the Apache docs for htaccess files are always a good place to start. The most common use is for per-directory authentication. Most server configuration directives are supported in a .htaccess file (provided that the server's AllowOverride says so), but some have different syntax.