Php .htaccess-重定向不起作用
public_html profile.php中有一个安全页面,用于检查用户是否登录。未登录时会重定向到login.php。它在我尝试访问时起作用,但在(末尾斜杠)时不起作用 这是我的.htaccessPhp .htaccess-重定向不起作用,php,.htaccess,Php,.htaccess,public_html profile.php中有一个安全页面,用于检查用户是否登录。未登录时会重定向到login.php。它在我尝试访问时起作用,但在(末尾斜杠)时不起作用 这是我的.htaccess <ifModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</ifModule>
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
index.php
<?php
$path = $_SERVER['REQUEST_URI'];
$chunks = explode("/", $path);
//print_r($chunks);
if($chunks[1] == "profile") {
if($chunks[2] != "") {
$profile_id = $chunks[2];
require_once("profile.php");
} else {
require_once("profile.php");
}
}
?>
profile.php
<?php
require_once("../includes/initialize.php");
if(!$session->is_logged_in()) {
redirect_to("login.php");
}
if(isset($_GET['id'])) {
$profile_id = $_GET['id'];
}
echo "This is the profile page of ID: ".$profile_id;
?>
这是因为后面的斜杠是一个目录,它与
-d
测试匹配
我用这一点来确保我从来没有一个尾随斜杠
## Redirect to remove trailing slashes on extensionless URL requests
# If requested URL ending with slash does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Externally redirect to remove trailing slash
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
哪里是
$\u GET['id']
来自?如果一些用户直接来自profile.php?id=1,那么它可以从GET访问id,如果他来自profile/1/那么在index.php im上设置profile\u id。那么当有人打开http://my-domain.com/profile/
而/profile/
是一个真实的目录吗?不是一个真实的目录。还是你没有回答问题的第一部分:)这会重定向到logout,然后再重定向到login.php,但除了一个空白页面外,没有其他内容。这是可行的,但现在不是了,我看不出有什么不可行的。我想你在解决问题后会报告错误。这是我清洁的第一天。哈哈,这会让我很痛苦;)如果您做了一些重大更改,请忘记将其添加到您的主题中:)以供其他人使用。