【发布时间】:2018-06-05 10:35:40
【问题描述】:
我的目标是防止用户弄清楚我为我的网站使用的脚本语言。我网站的网址结构是http://example.com/login/,即http://example.com/?page=login。
page 参数检查文件是否存在。例如,?page=login 将检查 login.php 文件是否存在,并将其作为请求的页面包含在 index.php 文件中加载。如果页面不存在,则 error.php 页面将被替换,并显示“页面未找到”。
我想在这些条件下触发错误页面(将 ?page=error 添加到查询中):
条件 1: 文件扩展名被添加到请求的 URI。 示例:http://example.com/login.php 甚至 index.php 文件, http://example.com/index.php
条件2:文件不存在。例子: http://example.com/notinserver.php 或 http://example.com/notinserver.whatever
条件 3: 文件扩展名不是 css、js、jpg、jpeg、gif 或 png 文件 (http://example.com/images/logo.jpg)。为了清楚起见, URI 不能有句点,除非它允许扩展,例如 http://example.com/css/style.css
条件4:写入http://example.com/index/时。网页 不需要包含自己。
我无法通过条件 1,因为由于默认页面 http://example.com/ 上的无限重定向或写入 index.php 时服务器向我抛出了内部错误。到目前为止,这是我所拥有的:
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]+)/ ?page=$1
RewriteCond %{REQUEST_URI} \.
RewriteRule . ?page=error [L]
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting