在CodeIgniter中重定向index.php [英] Redirect index.php in CodeIgniter
问题描述
我创建了一个CodeIgniter应用程序,现在我试图重定向url与index.php到urls没有它。
我当前的.htaccess是:
RewriteEngine On
RewriteBase /
#删除尾部斜杠(防止SEO重复内容问题)
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。+)/ $ $ 1 [L,R = 301]
#强制www
#子域,你可以将它们添加到
#列表中使用| (OR)regex运算符
RewriteCond%{HTTP_HOST}!^(www | subdomain)[NC]
RewriteRule ^(。*)$ http://www.plugb.com/$1 [L,R = 301]
#检查用户是否正在尝试访问有效的文件
#,例如图像或css文档,如果这不是真的,它会发送
#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网址?
谢谢你,
Gabriel。
在最后一个规则之前添加:
RewriteBase /
RewriteCond%{HTTP_HOST}!=
RewriteRule ^ index.php(/.*) ?$ http://%{HTTP_HOST} $ 1 [R = 301]
RewriteRule ^ index.php(/.*)?$ - [R = 404]
I created a CodeIgniter application and now I'm trying to redirect the urls with index.php to urls without it.
My current .htaccess is:
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]
The only problem is that the same page is accessible with and without the index.php.
For example:
http://www.plugb.com/index.php/games/adventure-rpg
and
http://www.plugb.com/games/adventure-rpg
Is there a way to redirect the index.php URLs?
Thank you, Gabriel.
Add this before the last rule:
RewriteBase /
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]
or to deny access:
RewriteRule ^index.php(/.*)?$ - [R=404]
这篇关于在CodeIgniter中重定向index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!