[英]How to modify .htaccess
當我鏈接到目錄中的文件時,我想在php程序中將該文件作為參數打開。
例如,我有一個目錄temp
,文件aa.txt
, bb.txt
和test.php
。 當我鏈接到aa.txt
,應該像test.php?f=aa.txt
一樣進行處理。
.htaccess文件中有哪些更改?
test.php中的代碼
<?php
$f=$_GET['f'];
if(@file_exists($f)){
$inhoud = file_get_contents($f);
}else{
$inhoud = "Not found\n";
}
print "hallo <hr>".$inhoud;
?>
您想使用mod_rewrite ,並在要應用到的目錄中的.htaccess文件中定義如下規則:
# Enable mod_rewrite
RewriteEngine on
# If the request is an actual file and not test.php...
RewriteCond %{REQUEST_FILENAME} !test.php$
RewriteCond %{REQUEST_FILENAME} -f
# ... then rewrite the URL to pass the filename as a parameter to test.php
RewriteRule /(.*)$ test.php?f=$1 [QSA]
RewriteEngine On
RewriteCond %{REQUEST_URI} !test.php #Do not rewrite the test.php file
RewriteCond %{REQUEST_URI} -f #Requested filename exists
RewriteRule (.*) test.php?f=$1 [QSA,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.