0

我的管理系统中有一个页面,路径如下:

http://192.168.1.253/xxxxxx/admin/view/news-items/issue/3

我正在尝试重写它,以便它指向:

http://192.168.1.253/xxxxxx/admin/view/news-items.php?issue=3

但是我似乎无法让它工作,因为页面显示但 php 无法检测到 $_GET 变量。我有 2 个 .htaccess 文件,一个在 xxxxxx 目录中,一个在 admin 目录中。他们来了:

xxxxxx:

RewriteEngine On    # Turn on the rewriting engine

RewriteRule  ^([^/.]+)/delete/(1-9)/?$ $1.php?delete=$2 [L]
RewriteRule  ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule  ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L] # one name string parameter

行政:

RewriteEngine On    # Turn on the rewriting engine

RewriteRule  ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule  ^([^/.]+)/(\d+)/?$ $1.php?id=$2 [L] # one id parameter
RewriteRule  ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/issue/(\d+)/?$ $1.php?issue=$2 [L] # one issue parameter
RewriteRule  ^([^/.]+)/(\d+)/(\d+)/?$ $1.php?id=$2&file_id=$3 [L] # two parameters

编辑

这是新代码:

xxxxxx:

RewriteEngine On    # Turn on the rewriting engine

#RewriteRule  ^([^/.]+)/delete/(\d+)/?$ $1.php?delete=$2 [L,QSA]
RewriteRule  ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
RewriteRule  ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L,QSA] # one name string parameter

行政:

RewriteEngine On    # Turn on the rewriting engine

#RewriteRule  ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
#RewriteRule  ^([^/.]+)/(\d+)/?$ $1.php?id=$2 [L,QSA] # one id parameter
RewriteRule  ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/issue/(\d+)/?$ $1.php?issue=$2 [L,QSA] # one issue parameter
RewriteRule  ^([^/.]+)/(\d+)/(\d+)/?$ $1.php?id=$2&file_id=$3 [L,QSA] # two parameters
4

1 回答 1

1

您需要[QSA]在重写规则中包含该标志:

RewriteRule  ^([^/.]+)/delete/(1-9)/?$ $1.php?delete=$2 [L,QSA]
RewriteRule  ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
# etc.

文档中:

修改查询字符串

默认情况下,查询字符串会原封不动地传递。但是,您可以在包含查询字符串部分的替换字符串中创建 URL。只需在替换字符串中使用问号来指示应将以下文本重新注入到查询字符串中。当您想删除现有的查询字符串时,只用问号结束替换字符串。要组合新旧查询字符串,请使用[QSA]标志。

于 2012-04-12T11:20:08.753 回答