【发布时间】:2018-02-15 06:24:51
【问题描述】:
默认情况下。 Codeigniter url 在每个 url 中都有 index.php,然后使用下划线。
我现在的配置。
在 Routes.php 中我设置了 $route['translate_uri_dashes'] = TRUE; 。这意味着当我尝试输入 example.some_path 时,它将转到 example.some-path
在我的 config.php 中。
$config['index_page'] = '';// remove'index.php';
我的 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
# Don't listing directory
Options -Indexes
ErrorDocument 403 http://example/404
# Origin setting
SetEnvIf Origin "http(s)?://(.+\.)?example\.com(:\d{1,5})?$" CORS=$0
Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS
Header merge Vary "Origin"
现在的问题。
1) 是的,example.com 或 example.com/somepath(没有 index.php)正在工作。但是 example.com/index.php 或 example.com/index.php/somepath 也仍然可用并且也可以工作。即使我没有 robots.txt 的索引,当访问者访问它时也会出现重复的内容错误。那么如何确保无法访问 index.php 的任何内容?使用 .htaccess?
2) 设置 $route['translate_uri_dashes'] = TRUE; 后,所有带下划线的链接都会自动转换为破折号(并在我点击包含下划线的网站中的链接时自动插入 index.php)..(例如:一旦我点击链接 <a href="http://example.com/some_path">my link</a> 它将转换为 example.com/index.php/some-path)。当我尝试直接访问 example.com/some-path 而不单击我网站上的任何链接时。是的,example.com/some-path 工作。
如何确保 index.php 无法访问并自动重定向到非 index.php?
【问题讨论】:
标签: php apache .htaccess codeigniter mod-rewrite