开发者

How to get file directory trough .htaccess by using `RewriteRule ^(.*)$ ?id=$1 [L,QSA]`?

How to get file directory trough .htaccess by using RewriteRule ^(.*)$ ?id=$1 [L,QSA]?

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 w开发者_C百科ithout manual adding %{DOCUMENT_ROOT}/some/dir/, like value localhost I get trough %{HTTP_HOST}?


If you do not use RewriteBase you need to tell mod-rewrite the real Directory Root /var/ww/mysite/some/dir in the rewrite rule. RewriteBase would take the location url and map it to the directory.

So you'll maybe end up with

 RewriteRule /var/ww/mysite/some/dir/(.*)$ ?id=$1 [L,QSA]

And trying to map some internal variables it may be

 RewriteRule %{DOCUMENT_ROOT}/some/dir/(.*)$ ?id=$1 [L,QSA]

But I'm unsure, I rarely use mod_rewrite in .htaccess -- I prefer Directory tags, and the file path management can be different in .htaccess (auto removal and adding of directory prefixes). If you do not find a solution try to ask Servfault, plenty of admins other there.


Actualy Apache still does not have pathinfo($,PATHINFO_DIRNAME), function like has PHP.

So on now there are solution on using %{REQUEST_URI}, like this example:

RewriteRule ^(.+)/$ /path-dirname/$1 [R=301,L]

may reset with:

RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^.+/$ %1 [R=301,L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜