easyphp .htaccess 规则

发布于 2024-12-25 02:47:14 字数 277 浏览 4 评论 0原文

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

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

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

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

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

谢谢

i need to rewrite rules in my installation of easyphp on windows 7.

i need to make sure the rules are loaded correctly and i don't have to create tons of rules. also, when i copy the .htaccess to my server (which is linux) i want to make sure its working properly.

i have no experience with this and here's what i found diging the internet:

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

now, if i have basic page like 'contact-us' its ok but if i have sub pages it does not. how can i create sub folders?

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

颜漓半夏 2025-01-01 02:47:14

这是您需要做的:

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] 这使得测试用例不敏感 - 之间的差异在扩展的 TestString 和 CondPattern 中,“AZ”和“az”都被忽略。该标志仅对 TestString 和 CondPattern 之间的比较有效。它对文件系统和子请求检查没有影响。

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

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

Here's what you need to do:

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]

This will allow you to have pages like:

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

/? Means the slash is optional

[NC] This makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored, both in the expanded TestString and the CondPattern. This flag is effective only for comparisons between TestString and CondPattern. It has no effect on filesystem and subrequest checks.

[L] The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed.

All the information about flags and rules: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文