.htacess 从 view/index.php?id=123 重写为 /view/123

问题描述 投票:0回答:1

我有一个名为

view
的目录。里面有index.php。

目前用户必须前往

mydomain.com/account/new/prescriptions/view/index.php?id=61312
才能查看数据。

如何使用 .htaccess 将其更改为

mydomain.com/account/new/prescriptions/view/61312

我已经尝试过以下方法:

# Specific rewrite for account/new/prescriptions/view
RewriteRule ^(account/new/prescriptions/view)/(\d+)$ $1 [END]

# Append .php extension for other requests
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ /$1.php [END]

但是,这会将网址从

index.php?id=61312
更改为
index?id=61312

php apache .htaccess
1个回答
0
投票

您可以使用这个单一规则:

# rewrite for /path/123 to /path/index.php?id=123
RewriteRule ^(.+)/(\d+)/?$ $1/index.php?id=$2 [L,QSA]

# Append .php extension for other requests
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ /$1.php [END]
© www.soinside.com 2019 - 2024. All rights reserved.