Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP如何制定重写规则?_Php_Apache_Mod Rewrite_Url Rewriting - Fatal编程技术网

使用PHP如何制定重写规则?

使用PHP如何制定重写规则?,php,apache,mod-rewrite,url-rewriting,Php,Apache,Mod Rewrite,Url Rewriting,第一次使用mod rewrite。请帮我制定这些规则 我希望将我的URL重写为以下页面: list.php?city=dallas>list/city/dallas profile.php?id=12>profile/zaknuman(从数据库检索用户名) story.php?id=33>故事/德克萨斯州没有蚂蚁(故事标题从db检索) 它应该匹配最后一个斜杠后a-z和a-z范围内的每个字符 另外两个我相信您需要将slug(“zaknuman”和“texas没有蚂蚁”)嵌入到数据库中,然后您可以从

第一次使用mod rewrite。请帮我制定这些规则

我希望将我的URL重写为以下页面:

list.php?city=dallas>list/city/dallas

profile.php?id=12>profile/zaknuman(从数据库检索用户名)

story.php?id=33>故事/德克萨斯州没有蚂蚁(故事标题从db检索)

它应该匹配最后一个斜杠后a-z和a-z范围内的每个字符

另外两个我相信您需要将slug(“zaknuman”和“texas没有蚂蚁”)嵌入到数据库中,然后您可以从数据库中检索slug并通过这种方式获取您的ID,vis:

RewriteRule profile/(.*)$ profile.php?slug=$1

RewriteRule story/(.*)$ story.php?slug=$1
最后2个匹配最后一个斜杠后的每个字符

编辑:别忘了确保在.htaccess文件或Apache配置中启用了“RewriteEngine”

它应该匹配最后一个斜杠后a-z和a-z范围内的每个字符

另外两个我相信您需要将slug(“zaknuman”和“texas没有蚂蚁”)嵌入到数据库中,然后您可以从数据库中检索slug并通过这种方式获取您的ID,vis:

RewriteRule profile/(.*)$ profile.php?slug=$1

RewriteRule story/(.*)$ story.php?slug=$1
最后2个匹配最后一个斜杠后的每个字符


编辑:别忘了确保在.htaccess文件或Apache配置中启用了“RewriteEngine”

别忘了标记字符串的开头。@Gumbo-是的,我故意留下了开头,因为OP没有提到他们使用的URL路径。不过,这一点很好-@gAMBOOKa,在规则的开头加上一个“^”,以匹配字符串的开头。别忘了标记字符串的开头。@Gumbo-是的,因为OP没有提到他们正在使用的URL路径,所以我故意不使用开头。不过这一点很好-@gAMBOOKa,在规则的开头加上一个“^”,以匹配字符串的开头。