如何通过使用`RewriteRule ^(.*)$?id = $ 1 [L,QSA]`获取通过.htaccess的文件目录? [英] How to get file directory trough .htaccess by using `RewriteRule ^(.*)$ ?id=$1 [L,QSA]`?
问题描述
如何使用RewriteRule ^(.*)$ ?id=$1 [L,QSA]
通过.htaccess获取文件目录?
How to get file directory trough .htaccess by using RewriteRule ^(.*)$ ?id=$1 [L,QSA]
?
如果.htaccess位于http://localhost/some/dir/.htaccess
中并且正在打开http://localhost/some/dir/here/I/use/RewriteRule/
,如何在不使用RewriteBase
且不手动添加%{DOCUMENT_ROOT}/some/dir/
的情况下检测值/some/dir/
,就像值localhost
一样,我会遇到槽%{HTTP_HOST}
?
If .htaccess is located in http://localhost/some/dir/.htaccess
and I'm opening http://localhost/some/dir/here/I/use/RewriteRule/
, how I detect value /some/dir/
without using RewriteBase
and without manual adding %{DOCUMENT_ROOT}/some/dir/
, like value localhost
I get trough %{HTTP_HOST}
?
推荐答案
Apache仍然没有pathinfo($,PATHINFO_DIRNAME)
,功能类似于PHP.
Actualy Apache still does not have pathinfo($,PATHINFO_DIRNAME)
, function like has PHP.
因此,现在有使用%{REQUEST_URI}
的解决方案,例如以下示例:
So on now there are solution on using %{REQUEST_URI}
, like this example:
RewriteRule ^(.+)/$ /path-dirname/$1 [R=301,L]
可能会重置为:
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^.+/$ %1 [R=301,L]
这篇关于如何通过使用`RewriteRule ^(.*)$?id = $ 1 [L,QSA]`获取通过.htaccess的文件目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!