我有一个名为
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
您可以使用这个单一规则:
# 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]