繁体   English   中英

如何修改.htaccess

[英]How to modify .htaccess

当我链接到目录中的文件时,我想在php程序中将该文件作为参数打开。

例如,我有一个目录temp ,文件aa.txtbb.txttest.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM