Change site URL in Apache with mod_rewrite

会有一股神秘感。 提交于 2019-12-11 22:45:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!