由于Wordpress%postname%permalinks,我的大部分网址都很好。
如果您提交修改,我仍然希望在编辑帖子时更改一些查询字符串,例如?edit = ,而?updated = true 。
有没有人能给我一个快速的例子,几乎没有评论我可以用来上班?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
// I have no idea what comes here
</IfModule>
1) www.mywebsite.com/post-template/?edit=3242&l; - 号码是帖子ID
如何在/ OR替换后仅显示帖子ID?编辑=用单词“potatoe”为例?
2) www.mywebsite.com/post-template/?updated=true<- - 我不知道如何更改,没有ID或任何内容
如何替换?updated = true,例如“胡萝卜”这个词?
我经常变得粗暴并开始测试,但我读到.htaccess中的错误会导致一些严重的问题。
答案 0 :(得分:1)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^edit/(.*)$ theprocess.php?edit=$1 [L]
RewriteRule ^edit/(.*)/submitit$ theprocess.php?edit=$1&updated=true [L]
</IfModule>
以上是您开始的示例(假设您正在使用的php文件称为process.php)。
您需要查看正则表达式,因为您将大量使用RewriteRules。重要的是$1
将替换为()
中的实际值,在这种情况下,.*
意味着&#34;匹配任何内容&#34;在那时候。因此,在示例中,如果一个类型http://example.com/edit/123
,则处理的是theprocess.php?edit=123