php - 在 CodeIgniter 中重定向 index.php

标签 php .htaccess codeigniter

我创建了一个 CodeIgniter 应用程序,现在我正在尝试将带有 index.php 的 url 重定向到没有它的 url。

我当前的 .htaccess 是:

RewriteEngine On
RewriteBase /

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

唯一的问题是使用和不使用 index.php 都可以访问同一页面。

例如:

http://www.plugb.com/index.php/games/adventure-rpg

http://www.plugb.com/games/adventure-rpg

有没有办法重定向 index.php 的 URL?

谢谢, 加布里埃尔。

最佳答案

在最后一条规则之前添加:

RewriteBase /    
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]

或拒绝访问:

RewriteRule ^index.php(/.*)?$ - [R=404]

关于php - 在 CodeIgniter 中重定向 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2861650/

相关文章:

php - 使用jquery设置php页面参数并在参数中添加值时出现问题

javascript - 如何制作单页网站

php - 将错误记录到文件中,但不显示在Codeigniter中

php - 当值有引号时,列值的字符串长度减一

PHP 报告在 copy() 时失败,但文件实际上已被复制

php - 使用 mysql 和 PHP 在选择下拉列表中分类

php - 为 3rd 方 JS 使用浏览器缓存

regex - 用于获取请求的文件大小的 .htaccess 规则

php - .htaccess 与 ^(.*)$ index.php/$1 给出 "No input file specified"

php - 如何在 codeigniter 中将变量从 View 传递到 Controller