[英]htaccess rewrite get parameter in subdirectory and retrieve with php
I try rewriting example.com/subdir/file.php?param=123
to example.com/subdir/file/123
and retrieve the value in php.我尝试将
example.com/subdir/file.php?param=123
重写为example.com/subdir/file/123
并检索 php 中的值。
In the .htaccess
in the main directory i wrote RewriteRule ^/subdir/([^/.]+)/?$ /subdir/file.php?param=$1 [L,NC,QSA]
but it's not working.在主目录的
.htaccess
中,我写了RewriteRule ^/subdir/([^/.]+)/?$ /subdir/file.php?param=$1 [L,NC,QSA]
但它不起作用。
You may try this rule in site root .htaccess:您可以在站点根目录 .htaccess 中尝试此规则:
RewriteRule ^(subdir/[\w-]+)/([\w-]+)/?$ $1.php?param=$2 [L,NC,QSA]
file
part also after subdir/
subdir/
之后匹配file
部分/
in regex pattern is not matched in .htaccess
.htaccess
中的前导/
正则表达式模式不匹配subdir/
.subdir/
中没有其他 .htaccess 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.