Codeigniter htaccess 删除 index.php 和 www

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
本文介绍了Codeigniter htaccess 删除 index.php 和 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我试图让我的 htaccess 重写规则从 url 中删除 index.php 并且还将 www. 请求重定向到非 www 版本.

I'm trying to get my htaccess rewrite rules to remove the index.php from the url AND also redirect the www. requests to the non-www version.

这是我的 htaccess,它可以很好地删除 index.php:

This is my htaccess which works fine with removing the index.php:

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

我遇到了另一个关于如何删除 www 部分的问题:

And I came across another question on how to remove the www part:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

但我似乎无法让他们一起玩得很好!任何意见/建议最感谢!

But I just cant seem to get them to play nicely together! Any advice/suggestions most appreciated!

推荐答案

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

RewriteEngine On开始"重写.RewriteCondRewriteRule 成对工作.在这里,我们首先将用户发送到非 www 版本,并清理 URL.

RewriteEngine On "starts" rewriting. RewriteCond and RewriteRule work as pairs. Here, we send user to non-www version first, and cleans URLs.

这篇关于Codeigniter htaccess 删除 index.php 和 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)
Break HTTP file uploading from server side by PHP or Apache(通过 PHP 或 Apache 从服务器端上传 HTTP 文件)