我有两页从mysql中选择数据。第一页 - readmore.php,从表格帖子中获取url
的帖子。第二页 - categories.php从表类别中获取caturl
的数据。
.htaccess中的readmore.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ readmore.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ readmore.php?url=$1
.htaccess中的categories.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ categories.php?caturl=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ categories.php?caturl=$1
我的问题位于获得caturl htaccess时将我重定向到readmore.php,但我想重定向到categories.php
答案 0 :(得分:2)
您正在将* .html重定向到新的网址readmore.php?url=*
,因此网址会发生变化。
由于网址现在为readmore.php?url=*
,因此第二组规则不会触发(不再存在与* .html匹配的模式)。
因此永远不会加载类别。您需要在网址中添加一个参数来区分不同的类型。
因此,请确保您的所有文章(或类别)在网址中都有一个共同部分,以表明它是该类型的网页。
示例:强>
RewriteRule ^article_([a-zA-Z0-9-/]+).html$ readmore.php?url=$1
RewriteRule ^cat_([a-zA-Z0-9-/]+).html$ categories.php?caturl=$1
因此,一篇名为article_firstpost.html
的文章会链接到readmore.php?url=firstpost
,而cat_cars.html
会链接到categories.php?caturl=cars