问题
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:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/1441140/change-site-url-in-apache-with-mod-rewrite