views:

62

answers:

2

hi

i how can i change my site URL using mod_rewrite my problem is when i open my site's admin section i have to write www.example.com/index.php/admin

what i want is i directly open my site like www.example.com/admin please help

thanks

+1  A: 

Here's a .htaccess file copied from the CodeIgniter PHP framework:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

This redirects everything that isn't index.php, robots.txt or anything in the images folder to index.php/$1, where $1 is the URL the user entered.

You need these rules as:

  • Redirecting index.php would cause an infinte loop - http://localhost/index.php/index.php/index.php/...
  • robots.txt is an important file that search engines use. It is just plain text; you don't want it handled by your code.
  • You obviously want to keep having access to your images. Adjust this path as necessary for where your static assets are located.
Lucas Jones
You rule would prevent any URL path that just *begins* with `index.php`, `images` or `robots.txt` to be rewritten.
Gumbo
+1  A: 

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php/ index.php%{REQUEST_URI} [L]

The condition is to exclude requests of existing files to be rewritten.

Gumbo
thanks a ton gumbo
vipinsahu