我想删除Codeigniter
自动附带的默认index.php
。
我已经能够删除这个代码
RewriteRule ^(.*)$ index.php/$1 [L]
example.com/blog
现在可以访问example.com/index.php/blog
后来我想用www
作为URL
的前缀,即example.com/blog
应该用这些重写规则重定向到www.example.com/blog
RewriteCond %{HTTP_HOST} ^(?!www'.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
在将上面的代码添加到我的.htaccess
文件的末尾后,它开始出现错误行为。
如果我在URL
栏中输入www.example.com/blog
,它可以正常工作,但如果我输入example.com/blog
,它会重定向到www.example.com/index.php/blog
我做错了什么?
我希望example.com/blog
重定向到www.example.com/blog
注意:我使用的是Codeigniter
框架。
添加:此代码只是在我之前的代码之上。也许这是问题所在,请帮忙!!!
RewriteCond $1 !^{index'.php|[assests/images/themes/fonts/style/scripts/js/install]|robot'.txt|favicon'.ico}
试试这个:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ example.com/$1 [L,R=301]
经过多次技巧和@Tpojka的帖子,我终于想出了这个
RewriteEngine On
RewriteBase /
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# no www -> www
RewriteCond %{HTTP_HOST} ^(?!www'.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
# 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]
这家伙是我的问题
RewriteCond $1 !^{index'.php|[assests/images/themes/fonts/style/scripts/js/install]|robot'.txt|favicon'.ico}
我需要帮助如何排除文件夹和一些文件,如robot.txt
文件,就像我在故障行中尝试的那样。
这是我个人使用的完整.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www'. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>