.htaccess 如何在php中使用htaccess更改已工作的GET查询和请求的GET数据
我确信,通过在stackoverflow中发布要求,我可以得到解决方案 我正在开发一个web应用程序,其中我有页面,每个页面的内部都有帖子、功能和问题。我在SQL.htaccess 如何在php中使用htaccess更改已工作的GET查询和请求的GET数据,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我确信,通过在stackoverflow中发布要求,我可以得到解决方案 我正在开发一个web应用程序,其中我有页面,每个页面的内部都有帖子、功能和问题。我在SQLposts和questions中有两个表。现在我想要的是: 1:当用户点击帖子链接(页面内部)时,用户必须重定向到一个带有SEO友好URL的帖子页面,该页面正在工作。 RewriteRule^pages/([\w-]+)/?$page.php?pages=$1[QSA,NC,L] RewriteRule^pages/([\w-]+)
posts
和questions
中有两个表。现在我想要的是:
1:当用户点击帖子链接(页面内部)时,用户必须重定向到一个带有SEO友好URL的帖子页面,该页面正在工作。
RewriteRule^pages/([\w-]+)/?$page.php?pages=$1[QSA,NC,L]
RewriteRule^pages/([\w-]+)/([\w-]+)/?$page.php?pages=$1&title=$2[QSA,NC,L]
页面
用于获取
页面查询titles
用于GET
post查询question
现在我需要在我用于postGET
查询的同一页面上进行GET
问题查询
2:当用户单击问题链接(页面内部)时,用户必须重定向到单个问题页面
工作example.com/pages/my page/my page first Post
必需的
example.com/pages/my page/my page第一个问题
此数据来自两个不同的
SQL表
以下是如何使用3个单独的规则:
RewriteEngine On
# /pages/my-page
RewriteRule ^pages/([\w-]+)/?$ page.php?pages=$1 [QSA,NC,L]
# for URI /pages/my-page/my-page-first-Post
RewriteRule ^pages/([\w-]+)/([\w-]+)/?$ page.php?pages=$1&title=$2 [QSA,NC,L]
# for URI /pages/my-page/q/my-page-first-Question
RewriteRule ^pages/([\w-]+)/q/([\w-]+)/?$ page.php?pages=$1&question=$2 [QSA,NC,L]
在page.php
代码中,您可以检查:
if (isset($_GET['question')) {
// question page
// work with $_GET['page') and $_GET['question')
} else if (isset($_GET['title')) {
// post page
// work with $_GET['page') and $_GET['title')
} else {
// single page
// work with $_GET['page')
}
/pages/my page/my page first Post
和/pages/my page/my page/my page first Question
遵循相同的结构,这就是为什么重写可以发生在?pages=$1&title=$2
或?pages=$1&Question=$2
上,但不能同时发生。您可以为问题页面添加一个标记,例如/pages/my page/question/my page first question
,以进行不同的处理。感谢您的时间,我按照您告诉?pages=$1&question=$2
的方式进行了操作,还可以更改结构href=“pages/my page/q/my page first question”
,但它不起作用,同时,我还为page questions.php
创建了一个新页面,其中我添加了isset(GET['question']{……}
查询也一样。但是出现了页面未找到错误。我希望您理解我要解释的内容。谢谢这太棒了,正如我所期望的那样工作得很好。现在我必须在我的url中添加最后一个部分,例如example.com/pages/my page/followers
,在这里我想显示关注我页面的用户总数。我创建了这样的内容,