【发布时间】:2012-08-28 21:51:14
【问题描述】:
如何使用 mod_rewrite 更改我的网站 URL 我的问题是当我打开网站的管理部分时,我必须写 www.example.com/index.php/admin
我想要的是直接打开我的网站,例如 www.example.com/admin 请帮助
谢谢
【问题讨论】:
标签: apache .htaccess mod-rewrite
如何使用 mod_rewrite 更改我的网站 URL 我的问题是当我打开网站的管理部分时,我必须写 www.example.com/index.php/admin
我想要的是直接打开我的网站,例如 www.example.com/admin 请帮助
谢谢
【问题讨论】:
标签: apache .htaccess mod-rewrite
这是从CodeIgniter PHP 框架复制的.htaccess 文件:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
这会将不是index.php、robots.txt 或images 文件夹中的所有内容重定向到index.php/$1,其中$1 是用户输入的URL。
你需要这些规则:
index.php 会导致无限循环 - http://localhost/index.php/index.php/index.php/...
robots.txt 是搜索引擎使用的重要文件。它只是纯文本;您不希望它由您的代码处理。【讨论】:
index.php、images 或robots.txt 开头开始的 URL 路径被重写。
试试这个规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php/ index.php%{REQUEST_URI} [L]
条件是排除现有文件的重写请求。
【讨论】: