Php 如何使用重写规则接吻(Apache)
我正在编写一个小的web应用程序,我需要做一些重写规则,因为我很懒,不想用PHP来做。 我看到我自己写了很多规则,也许什么都没有,所以我寻求你的建议和帮助 注: 我需要满足这个计划: 另外:Php 如何使用重写规则接吻(Apache),php,apache,mod-rewrite,Php,Apache,Mod Rewrite,我正在编写一个小的web应用程序,我需要做一些重写规则,因为我很懒,不想用PHP来做。 我看到我自己写了很多规则,也许什么都没有,所以我寻求你的建议和帮助 注: 我需要满足这个计划: 另外: 它不能阻止现有文件夹:(这部分可以很容易地编写脚本,为应用程序根目录下的每个文件夹添加重写规则。) 如果有一个名为image的目录,并且我使用浏览,我将访问image,并且我不应该在$\u get['title']变量中获取/image/test.png 它不能阻止真正的文件,如果我想,我应该有它。如果
- 如果有一个名为image的目录,并且我使用浏览,我将访问image,并且我不应该在$\u get['title']变量中获取/image/test.png
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*).php(/?$) $1.php [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(\w*\b)(/?$) index.php?title=$4 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})(/?$) index.php?year=$1&month=$2&day=$3 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)(/?$) index.php?year=$1&month=$2&day=$3&page=$4 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})(/?$) index.php?year=$1&month=$2 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/page/([0-9]+)(/?$) index.php?year=$1&month=$2&page=$3 [L,QSA]
RewriteRule ^([0-9]{4})(/?$) index.php?year=$1 [L,QSA]
RewriteRule ^([0-9]{4})/page/([0-9]+)(/?$) index.php?year=$1&page=$2 [L,QSA]
RewriteRule ^(archives\b)(/?$) _cache/archive.html [L,QSA]
RewriteRule ^(feed\b)(/?$) /_atom.xml [L,QSA]
RewriteRule ^page/([0-9]+)(/?$) index.php?page=$1 [L,QSA]
RewriteRule ^([^_/].*)(/?$) index.php?title=$1 [L,QSA]
</IfModule>
重新启动发动机
重写规则^(.*).php(/?$)$1.php[L,QSA]
重写规则^([0-9]{4})/([0-9]{2})/([0-9]{2})/(\w*\b)(/?$)index.php?title=$4[L,QSA]
重写规则^([0-9]{4})/([0-9]{2})/([0-9]{2})(/?$)index.php?年=1美元,月=2美元,日=3美元[L,QSA]
重写规则^([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)(/?$)index.php?年=$1,月=$2,日=$3,页=$4[L,QSA]
重写规则^([0-9]{4})/([0-9]{2})(/?$)index.php?年=1美元,月=2美元[L,QSA]
重写规则^([0-9]{4})/([0-9]{2})/page/([0-9]+)(/?$)index.php?年=1美元,月=2美元,页=3美元[L,QSA]
重写规则^([0-9]{4})(/?$)index.php?年份=$1[L,QSA]
重写规则^([0-9]{4})/page/([0-9]+)(/?$)index.php?年份=1美元,页面=2美元[L,QSA]
重写规则^(archives\b)(/?$)\u cache/archive.html[L,QSA]
重写规则^(feed\b)(/?$)/_atom.xml[L,QSA]
重写规则^page/([0-9]+)(/?$)index.php?page=$1[L,QSA]
重写规则^([^ _/].*)(/?$)index.php?title=$1[L,QSA]
但是它不适用于/image/example,我觉得我正在走一条不好的道路。。。我重复一遍,我不想用PHP处理这个问题。我真的认为这条规则对我来说更灵活
非常感谢您的帮助和指导
希望我的英语很好,因为它不是我的母语。如果你能应付没有标题的情况。然后我建议更改最后一行:
RewriteRule ^([^_/][^\.]*)(/?$) index.php?title=$1 [L,QSA]
编辑:最后一条规则几乎匹配所有不带“uu”的内容,因此您需要提供一些常规的exp匹配,以便它理解文件。如果文件/文件夹不存在,则重定向: (您可以将其与重写规则相结合(否)
修理 显然mod_rewrite不处理组名和非捕获组 在您接受某些答案之前,这里有一个演示(稍后将编辑此内容):
为什么不把这些都集中在一起呢
^(?<year>[0-9]{4})(/(?<month>[0-9]{2})(/(?<day>[0-9]{2}))?)?(/page/(?<page>[0-9]+))?/?\s*$
index.php?year=$year&month=$month&day=$day&page=$page
你的英语不错,但我真的很喜欢这个标题:D@The厄运之人:接吻-保持简单,愚蠢(以防你不知道:P)@n00b我知道,但它仍然很有趣。
RewriteRule ^([^_/][^\.]*)(/?$) index.php?title=$1 [L,QSA]
RewriteEngine On
RewriteRule ^([0-9]{4})(/([0-9]{2})(/([0-9]{2}))?)?(/page/([0-9]+))?/?\s*$ index.php?year=$1&month=$3&day=$5&page=$7 [L,QSA]
^(?<year>[0-9]{4})(/(?<month>[0-9]{2})(/(?<day>[0-9]{2}))?)?(/page/(?<page>[0-9]+))?/?\s*$
index.php?year=$year&month=$month&day=$day&page=$page
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(\w*\b)(/?$) index.php?title=$4 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})(/?$) index.php?year=$1&month=$2&day=$3 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)(/?$) index.php?year=$1&month=$2&day=$3&page=$4 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})(/?$) index.php?year=$1&month=$2 [L,QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/page/([0-9]+)(/?$) index.php?year=$1&month=$2&page=$3 [L,QSA]
RewriteRule ^([0-9]{4})(/?$) index.php?year=$1 [L,QSA]
RewriteRule ^([0-9]{4})/page/([0-9]+)(/?$) index.php?year=$1&page=$2 [L,QSA]