- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近做了一些研究,以了解如何修改我的 .htaccess 文件以隐藏 URL 中的 .php 扩展名。我使用以下代码让它按照我想要的方式工作:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.guitrum.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.guitrum.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
ErrorDocument 404 /404.php
DirectoryIndex index.php
不幸的是,我的 php 脚本的一部分现在被破坏了。请记住,在修改我的 .htaccess 文件之前,一切正常。在登录页面上,我有一些脚本可以使用 POST 方法传递一些用户输入,如下所示:
<form method='POST' action='loginconfirm.php'>
Password: <input type='password' name='password'></input>
<input type='submit' name='submit' value='Go'></input>
</form>
在loginconfirm.php页面上,我有一个加密类作为页面中的包含文件,代码如下:
<?php
//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
class Encryption {
const CYPHER = MCRYPT_RIJNDAEL_256;
const MODE = MCRYPT_MODE_CBC;
const KEY = 'SecretKey';
public function encrypt($plaintext) {
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, self::KEY, $iv);
$crypttext = mcrypt_generic($td, $plaintext);
mcrypt_generic_deinit($td);
return rawurlencode(base64_encode($iv . $crypttext));
}
public function decrypt($crypttext) {
$crypttext = rawurldecode($crypttext);
$crypttext = base64_decode($crypttext);
$plaintext = '';
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, self::KEY, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return trim($plaintext);
}
}
//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
?>
我在页面上做的第一件事是设置一个新变量,该变量对密码进行了加密,如下所示:
<?php
include ("includefiles/EncryptionUtilities.php");
$passworde = Encryption::encrypt($_POST['password']);
setcookie('password', $passworde, time() + (60 * 5));
?>
正常情况下它可以正常工作,但现在它会抛出错误:
an empty string was passed into EncryptionUtilities.php, and cannot modify header information - headers already sent.
我认为 .htaccess 文件存在问题,不允许 POST 方法在页面之间进行通信。
最佳答案
使用外部重定向 POST 数据不会重定向并且会丢失。将您的 .php
规则替换为:
# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /.+?\.php [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]
关于php - 更改我的 .htaccess 文件后,我的 php 上的 POST 方法不再起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518711/
是否可以在 .htaccess 中包含来自另一个 htaccess 文件的规则? .htaccess RewriteEngine On RewriteCond ... RewriteRule ...
我正在尝试做的事情: 在我的特定项目的服务器上,我想通过 htaccess 编写 URL 重写规则(从 URL 中删除 .php 或 .html 扩展名)。 我的网站网址: http://enacte
在我的 .htaccess 文件中我已经有一些重写条件和规则,并且它工作正常。 现在我需要将“http 到 https 重定向”添加到我的 htaccess 文件中。 这是我的旧 .htaccess
注意:我写了解决方案。不管怎样,谢谢你。 :) 我知道这似乎是重复的问题:我搜索了很多,我应用了数十条重写规则,但它们不起作用。 我需要从 重定向 www.domain.com/folder1 到 w
我有一个带有 drupal 的多站点,我创建了一个站点,该站点起初应该可以通过多种方式(子域和路径)访问,但现在我只想保留其中一个;所以我应该重定向所有其他人。现在我有: aaa.domain.com
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我将我的网站从/v1/etc... 目录移动到/v2/etc... 目录,并希望在 htaccess 中进行永久重定向。有人能帮我吗? 最佳答案 您可以使用 mod_rewrite : Rewrite
我想通过 .htaccess 保护文件夹。以下不起作用。它在浏览器中显示登录对话框,但看起来好像用户名和密码不匹配。当我将方法更改为 Basic 时,它运行良好。 AuthUserFile /home
任何人都可以解释以下行吗? RewriteRule ^(.*)$ /index.php/$1 [L] 最佳答案 重写规则的部分分解如下: 重写规则 表示此行将是重写规则,而不是重写条件或其他重写引擎指
我正在尝试从一个域中一个目录中的所有文件创建一个永久的 htaccess 重定向(301)到另一个域,如下所示: 重定向以下目录中的所有文件: http://www.primary.com/apple
我不是 .htaccess 的英雄,但我遇到了一个我认为可能是由它引起的问题。 第一个症状:对我的数据库的简单更改(如用户 IP 跟踪)每次请求都完成了多次,而站点的输出看起来还不错。 经过数小时的跟
我想做一个类似basecamp.com的东西:你公司的名字变成三级域名,http://mycompany.basecamp.com例如。我知道它(很可能)是在.htaccess文件和mod_rewri
我已阅读 this这对我的要求来说似乎太长了。 并尝试过 Redirect /index.php /index2.php但它不起作用(内部服务器错误) 我想要的是将我的一些 php 文件重定向到 in
如果使用此代码,则成功: Redirect 301 /products.php http://website.com.au/product_123.php 但是,如果执行此操作,则不是: Redire
我想重定向这个子域: http://abc.domain-name.com 到根域上使用相同名称的文件夹: http://www.domain-name.com/abc 这样,如果我尝试访问以下文件:
我已经在我的实时站点上设置了 htpasswd 身份验证,并且效果很好,但是当我在开发环境中工作时,我不想被要求输入密码。 在我的 httpd.conf 文件中,我有: SetEnv APP_ENV
之前 我安装了 SSL,一切运行良好!!这是我的根网络服务器 .htaccess 文件中的代码: Options +MultiViews RewriteEngine On RewriteCond %{
我要问一个非常简单的问题。当我运行我的页面时,我不希望我的链接显示这个: http://localhost/example/assets/gallery.php 我想要的是: http://local
我在 htaccess 中有说明,可以让所有请求都通过 index.php 文件。但它禁止访问文件夹和文件。因此,如果我尝试转到/uploads/products/thumbs/file.png 它会
我有一个这样的网址:https://example.com/coins/1&order_by=today以及几个类别,例如: https://example.com/coins/1&order_by=
我是一名优秀的程序员,十分优秀!