windows - easyphp .htaccess 规则

标签 windows .htaccess mod-rewrite easyphp

我需要在 Windows 7 上安装 easyphp 时重写规则。

我需要确保正确加载规则,而不必创建大量规则。此外,当我将 .htaccess 复制到我的服务器(Linux)时,我想确保它正常工作。

我没有这方面的经验,这是我在互联网上发现的:

RewriteRule (.*) index.php?s=$1

现在,如果我有像“联系我们”这样的基本页面,那没问题,但如果我有子页面,那就不行了。如何创建子文件夹?

谢谢

最佳答案

这是您需要做的:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\-]+)/?$ index.php?main=$1 [NC,L] 
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ index.php?main=$1&sub=$2 [NC,L]

这将使您拥有如下页面:

http://www.domain.com/mainpage/ or
http://www.domain.com/mainpage or
http://www.domain.com/mainpage/subpage/ or
http://www.domain.com/mainpage/subpage

/? 表示斜杠是可选的

[NC] 这使得测试用例不敏感 - 'A-Z' 和 'a-z' 之间的差异在扩展的 TestString 和 CondPattern 中都被忽略。此标志仅对 TestString 和 CondPattern 之间的比较有效。它对文件系统和子请求检查没有影响。

[L] [L] 标志导致 mod_rewrite 停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理进一步的规则。

关于标志和规则的所有信息:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

关于windows - easyphp .htaccess 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8736909/

相关文章:

apache - URL 中的可选参数 - 重写规则

python - 如何在 Windows (Python) 上安装 leveldb

windows - 32 位和 64 位进程之间的 memcpy 性能差异

wordpress - IP 规范化 (WordPress)

php - 在 php 脚本中访问重写的 URI

regex - 为特定网址强制使用 HTTPS

c++ - C++中是否有任何API可以找到机器的环回IP地址?

c# - HWND 可见吗?

.htaccess - 子文件夹html文件中漂亮url的htaccess规则

apache - https 的 htaccess 文件错误 500