如何检测mod_rewrite是否可用? [英] How to detect if mod_rewrite is available?

查看:525
本文介绍了如何检测mod_rewrite是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.我的应用程序中的链接有问题.我想使用"pretty-urls'",所以我希望所有链接看起来都像"www.sitename.com/controller/method".所以我想通过一个函数打印我所有的链接,就像

Good day. I have a problem with links in my application. I want to use 'pretty-urls',so i want to all my links look like 'www.sitename.com/controller/method'. So i want to print my all my links through one function,which would look like

function link($url_segments) {
  if(mod_rewrite_is_available) 
     return BASE_URL.$url_segments;
  else
     return BASE_URL."index.php".$url_segments;
}

但是我不明白如何检测服务器是否启用了重写模块.我找到了2个解决方案:

But i can't understand how to detect if server has rewrite module enabled. I have found 2 solutions:

  1. 在配置中放置一些变量(如codeigniter所做的),例如 $config["index_variable"]可以在我的函数中使用,但这意味着 我所有的客户都需要在配置时更改该行 在主机上安装应用程序
  2. 使用函数来检测mod_rewrite,就像apache_get_modules一样,但是像 我了解某些托管服务可能不可用,如果 服务器将是Nginx吗?
  1. Place in config some variable(like codeigniter does) like $config["index_variable"] to use inside my function,but that means that all my clients will need to change that line in config when installing application on hosting
  2. Use function to detect mod_rewrite,like apache_get_modules,but like i understood it can be not avaibale on some hosting,and what if server will be nginx?

所以我想知道如何检测并打印我的链接.

So i want to know,how to detect that and print my links.

感谢大家的帮助.

推荐答案

这可能非常棘手和困难,就我个人而言,我会使用后备方法.

This can be very tricky and hard, personally, I would go with the fallback approach.

  1. 查看apache2handler的已加载模块(通过 phpinfo() )以查看mod_rewrite是否为在那里
  2. 尝试sudo apache2ctl -t -D DUMP_MODULES查看是否已加载mod_rewrite
  3. 尝试使用.htaccess文件查看是否一切正常.
  4. 尝试确定使用的服务器软件,并解析服务器的conf文件
  5. 使用最坏的情况,即未启用mod_rewrite,然后在安装软件后手动启用它.
  1. Look at apache2handler's loaded modules (via phpinfo()) to see if mod_rewrite is there
  2. Try sudo apache2ctl -t -D DUMP_MODULES to see if mod_rewrite is loaded
  3. Try to use a .htaccess file to see if everything is working.
  4. Try to determine the server software used, and parse the conf file for the server
  5. Use worst case of no mod_rewrite is enabled, and then enable it manually after the software has been installed.

这篇关于如何检测mod_rewrite是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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