重定向到/ WWW加入URL中的codeigniter基于项目 [英] redirecting-to/adding www in url codeigniter based project

查看:116
本文介绍了重定向到/ WWW加入URL中的codeigniter基于项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加www和重定向所有非www网址到www的网址在$ C $基于cigniter项目,但这样做后,我的职务数据不能正常工作。这里是Apache 的.htaccess 文件的内容:

I am trying to add www and redirect all non-www urls to www urls in a codeigniter-based project, but my post data is not working after doing so. Here is the content of the Apache .htaccess file:

RewriteCond %{HTTP_HOST} ^examplesite\.com$ [NC]
RewriteRule ^(.*)$ http://www.examplesite.com/$1 [R=301,L]

$配置['uri_protocol'] ='自动';

一切就像一个魅力,如果我没有WWW的URL。我曾尝试 REQUEST_URI ,但它也不能工作。

Everything works like a charm if I do not have www urls. I have tried REQUEST_URI, but it didn't work either.

推荐答案

这是因为浏览器不会重新提交POST数据如果响应重定向。这是一个正常和意料之中的事情。你可以做的是只重写一个额外条件GET请求:

This is because browsers wont resubmit POST data if the response is a redirect. This is a normal and expected thing. What you can do is to only rewrite GET requests with an extra condition:

RewriteCond %{REQUEST_METHOD} GET [NC]
RewriteCond %{HTTP_HOST} ^examplesite\.com$ [NC]
RewriteRule ^(.*)$ http://www.examplesite.com/$1 [R=301,L]

留在的application / config / config.php文件 $配置['SITE_URL'] 选项为空字符串(这将使CI做自动检测),并在您的视图code,使用的 SITE_URL() 助手或的表单生成器功能的所以它会使用该请求进来的域。

Leave the $config['site_url'] option in application/config/config.php to an empty string (that will make CI do autodetect) and in your view code, use the site_url() helper or the form builder functions so it will use the domain that the request came in.

这篇关于重定向到/ WWW加入URL中的codeigniter基于项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆