简体   繁体   English

可选子目录内部重定向,Htaccess

[英]Optional Subdirectory Internal Redirect, Htaccess

I currently use this code to silently call another php file by using the file name as a get parameter: 我目前使用此代码通过将文件名用作get参数来静默调用另一个php文件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  blog/([^/]+)/?$  [NC]
RewriteRule .*   repost_p.php?post=%1  [L]

what if I wanted to make the file name a fake subdirectory, and add a file name as a second get parameter? 如果我想使文件名成为伪造的子目录,并添加文件名作为第二个get参数,该怎么办?

how would I go about doing that? 我将如何去做?

You could just use something like: 您可以使用类似:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/blog/(.*)   /repost_p.php?path=$1  [L]

Then in the repost_p.php file you can filter the path variable to find out the subdirectories. 然后,在repost_p.php文件中,您可以过滤路径变量以找出子目录。

$path = isset($_GET['path']) ? $_GET['path'] ? '';
$params = explode('/', $path);

//params is now an array with all subdirectories.
//Make sure you validate each one for valid input! This can also be used for sql injection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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