【问题标题】:url re-write php pages not workingurl重写php页面不起作用
【发布时间】:2014-11-05 13:01:42
【问题描述】:

我有一个类似https://www.bookspk.site/category/cat.php?caturl=islamic-literature&Page=2 的网址 我可以将https://www.bookspk.site/category/cat.php?caturl=islamic-literature 重定向到https://www.bookspk.site/category/islamic-literature

RewriteRule ^([a-zA-Z0-9-/]+)$ cat.php?caturl=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ cat.php?caturl=$1

但无法将http://e.bookspk.net/category/cat.php?caturl=islamic-books&Page=2 转换为http://e.bookspk.net/category/islamic-books/2 使用此代码

RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$    cat.php?caturl=$1&page=$2 

已加载页面,但在所有页面上都显示第一页的内容,请帮助

【问题讨论】:

  • 您的 htaccess 在/category/ 目录中吗?你能显示完整的 .htaccess 吗?
  • 是的,我在类别目录中的 .tacces 文件和完整文件是 RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ cat.php?caturl=$1&page=$2 RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ cat.php?caturl=$1&page= $2

标签: php .htaccess url url-rewriting


【解决方案1】:

你可以使用

RewriteEngine On
RewriteBase /category/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ cat.php?caturl=$1&page=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ cat.php?caturl=$1 [L,QSA]

【讨论】:

  • 已加载 e.bookspk.net/category/islamic-books/2,但在每个页面上都显示首页内容
  • 我不知道cat.php 中的代码,但您可以在cat.php 之上使用print_r($_GET); exit; 来查看那里接收到的GET 参数。
  • 我做了,结果:Array ([caturl] => urdu-digests [page] => 2)
  • 这意味着规则有效,因为您正确获得了page=2。您只需要修复 cat.php 以使用 $_GET['page'] 显示正确的页面
  • 我正在使用 $_GET['page'] 并且当加载页面 e.bookspk.net/category/cat.php?caturl=islamic-books&Page=2 它显示正确的值
猜你喜欢
  • 2021-02-24
  • 2016-12-16
  • 2017-09-21
  • 2014-12-26
  • 2014-06-06
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 2016-12-18
相关资源
最近更新 更多