使用Apache的mod_rewrite来隐藏脚本扩展 [英] Using Apache's mod_rewrite to hide scripts extension

查看:53
本文介绍了使用Apache的mod_rewrite来隐藏脚本扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apache的mod_rewrite模块,我可以保存* .php文件并将它们加载为

* .html文件:


#制作http / /example.com/foo/bar.html加载/home/site/foo/bar.php

RewriteEngine On

RewriteRule ^(。*)\.html $ $ 1.php [L]


但是,是否有任何优雅的方法可以防止直接访问

" http // example.com / foo / bar .PHP" ;?无论L是什么flag,all * .html

请求使用我编写的任何* .php规则再次解析,即使

重写不会强制浏览器重定向,即使我使用NS

标志: - ?


我仍​​然可以在PHP中限制它(我可以考虑检查值

$ _SERVER [''REQUEST_URI'']),但我想知道为什么L和NS没有像我预期的那样工作


对不起,如果这个有点offtopic但我的新闻服务器没有提供任何

Apache组。

-

- http://alvaro.es - álvaroG。Vicario - 西班牙布尔戈斯

- Mi sitiosobreprogramación web: http://bits.demogracia.com

- - Mi web de humor al ba?oMaría: http://www.demogracia.com

-

With Apache''s mod_rewrite module I can keep *.php files and load them as
*.html files:

# Make http//example.com/foo/bar.html load /home/site/foo/bar.php
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

But, is there any elegant way to prevent direct access to
"http//example.com/foo/bar.php"? No matter the "L" flag, all *.html
requests get parsed again with any *.php rule I write, even though the
rewriting does not force a browser redirect and even if I use the NS
flag :-?

I still can restrict it in PHP itself (I can think of checking the value
of $_SERVER[''REQUEST_URI'']), but I''d like to understand why L and NS do
not work as I expected.
Sorry if this is kinda offtopic but my news server does not provide any
Apache group.
--
-- http://alvaro.es - álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al ba?o María: http://www.demogracia.com
--

解决方案


1.php [L]


但是,有什么优雅的方法可以防止直接访问

" http // example.com / foo / bar.php"?无论L是什么flag,all * .html

请求使用我编写的任何* .php规则再次解析,即使

重写不会强制浏览器重定向,即使我使用NS

标志: - ?


我仍​​然可以在PHP中限制它(我可以考虑检查值

1.php [L]

But, is there any elegant way to prevent direct access to
"http//example.com/foo/bar.php"? No matter the "L" flag, all *.html
requests get parsed again with any *.php rule I write, even though the
rewriting does not force a browser redirect and even if I use the NS
flag :-?

I still can restrict it in PHP itself (I can think of checking the value
of


_SERVER [''REQUEST_URI'']),但我想了解L和NS为什么没有像我预期的那样工作
。 br />
很抱歉,如果这有点异常,但我的新闻服务器没有提供任何

Apache组。

-

- http://alvaro.es - álvaroG。Vicario - 西班牙布尔戈斯

- Mi sitiosobreprogramaciónweb: http://bits.demogracia.com

- Mi web de humor al ba?oMaría: http:/ /www.demogracia.com

-
_SERVER[''REQUEST_URI'']), but I''d like to understand why L and NS do
not work as I expected.
Sorry if this is kinda offtopic but my news server does not provide any
Apache group.
--
-- http://alvaro.es - álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al ba?o María: http://www.demogracia.com
--


这篇关于使用Apache的mod_rewrite来隐藏脚本扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆