我创建了一个 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/