2013-03-04 17 views
4

我需要動態獲取我的.htaccess文件所在的當前目錄。那可能嗎 ? (一個變量可能?)。如何引用htaccess中的當前目錄

喜歡的東西:%{SCRIPT_FILENAME}

預先感謝您。

編輯:如果使用正則表達式?它應該是什麼樣子?

+1

沒有你檢查這個[列表](http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html#Mod_Rewrite_Variables)? – 2013-03-04 11:00:22

+1

我是這個幫助 http://stackoverflow.com/questions/1200348/how-do-i-make-htaccess-work-on-the-current-directory-and-not-subdirectories – 2013-03-04 11:33:33

回答

2

實際上Apache仍然沒有像PHP那樣的pathinfo($,PATHINFO_DIRNAME)函數。

等,已經出現了基於%{REQUEST_URI}的使用的解決方案,這樣的例子:

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

關於您的問題,這可能會爲你工作:

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