简单的 Mod 重写 [英] Simple Mod Rewrite

查看:22
本文介绍了简单的 Mod 重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 mod 重写来简单地打开这些链接:

I'm trying to create a mod rewrite to simply turn these links:

/index.php?page=home
/?page=home

进入

/home

有人可以告诉我这是怎么做的吗?在我们讨论这个主题时,是否有任何关于 mod 重写的好资源可供阅读?到目前为止,我最大的困难是我看不到任何调试它的方法.事情要么有效,要么无效.

Can someone show me how this is done? While we're on the subject, are there any good resources to read up on mod rewrite? My biggest struggle so far is that I don't see any way of debugging it; things either work or they don't.

推荐答案

有多种方法可以做到这一点.这个规则适用于任何不存在的文件:

There are a variety of ways to do this. This one applies the rule to any non-existent file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L]

您可能需要在顶部添加 RewriteEngine on,这会在您的 Web 文档根目录中的 .htaccess 中添加.当然,所有这些都取决于您的 Web 主机是否允许使用 htaccess (mod_rewrite) 以及规则覆盖文件是否应命名为 .htaccess.不过两者都很常见,所以应该没有问题.

You may have to add RewriteEngine on at the top, and this goes in .htaccess in your web document root. All of this, of course, depends on whether use of htaccess (mod_rewrite) is allowed by your web host and whether the rule override file should be named .htaccess. Both are pretty common though, so it shouldn't be a problem.

这篇关于简单的 Mod 重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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