PHP重定向VS htaccess的,这是更好? [英] php redirect vs htaccess which is better?

查看:155
本文介绍了PHP重定向VS htaccess的,这是更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问我的网站谁访问 http://www.domain.com/user/ xyz.php 的被重定向到 https://www.domain.com/user/ xyz.php

I want visitors to my site who visit http://www.domain.com/user/xyz.php to be redirected to https://www.domain.com/user/xyz.php.

IE浏览器。如果他们内的任何地方/用户/他们在安全的地方。因此必须重定向到https

ie. if they are anywhere inside /user/ they're in the secure location. so must be redirected to https

我的问题不是具体怎么实现这一点,但哪种方法更好呢?

我的直觉说,我应该使用的.htaccess重写规则 但我也认为是这样的:

My gut feeling says I should use a .htaccess Rewrite rule but I also considered something like:

    <?php
    if (!$_SERVER['HTTPS'] && strstr('user', $_SERVER['REQUEST_URI'])){
        header('location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
    }

我想听到的效率和安全性的意见,以及其他方面的考虑。

I'd like to hear opinions on efficiency and security as well as other considerations.

推荐答案

htaccess的可能是更有效的,特别是在内存使用的区域。服务器不需要加载PHP和PHP不需要解析和执行脚本。 Apache需要阅读和应用htaccess的配置为好,虽然,但不会消耗尽可能多的内存,因为PHP。

htaccess is probably more efficient, especially in the area of memory usage. The server doesn't need to load PHP, and PHP doesn't need to parse and execute a script. Apache needs to read and apply the configuration in htaccess as well, though, but that won't consume as much memory as PHP.

至于PHP中,执行速度也被PHP加载的方式确定,并且如果例如,APC的高速缓存时,或不

As for PHP, the speed of execution is also determined by the way PHP is loaded, and if, for instance, APC cache is used or not.

所以,虽然一般来说我觉得htaccess的应该是更有效的,我会做一个基准,如果你真的想,以确保您的配置。

So, while in general I think htaccess should be more efficient, I would do a benchmark if you really want to be sure for your configuration.

但在一般情况:不用太担心了。选择什么似乎是最好的。这不应该是一个瓶子颈部相比实际脚本执行与真正的功能性。

But in general: don't worry too much about it. Choose what seems best. This shouldn't be a bottle neck compared to actual script execution with real functionality.

这篇关于PHP重定向VS htaccess的,这是更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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