开发者

URL rewriting using .htaccess, query string as file name

If my URL is http://www.x开发者_运维百科yz.com/index.php?view=abc then it should open http://www.xyz.com/abc.php

What should I write in .htaccess??

Thanks in advance.


If my URL is http://www.xyz.com/index.php?view=abc then it should open http://www.xyz.com/abc.php

You don't need .htaccess for that, simply put in index.php

$view = $_GET['view'];
if (strpos($view, '/') === false && $view != "index" && file_exists("$view.php"))
  require "$view.php";

Be sure not to have any other vulnerable php files in your root directory (but I'd recommend using other/better techniques to check the user input from the url).


If you wanted to have the rewriting the other way round, your .htaccess could look similar to this:

RewriteEngine on

RewriteCond %{REQUEST_URI}  !^/index.php
RewriteRule ^([a-z]+).php$  /index.php?view=$1  [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜