如何通过使用`RewriteRule ^(.*)$?id = $ 1 [L,QSA]`获取通过.htaccess的文件目录? [英] How to get file directory trough .htaccess by using `RewriteRule ^(.*)$ ?id=$1 [L,QSA]`?

查看:147
本文介绍了如何通过使用`RewriteRule ^(.*)$?id = $ 1 [L,QSA]`获取通过.htaccess的文件目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆