【发布时间】:2019-10-25 14:52:29
【问题描述】:
我尝试重定向到一个站点并跳转到该站点上的锚点。
锚是#tab-5
我试过了:
window.location.href = "/property/details?id=123#tab-5";
和
window.location.replace("/property/details?id=123#tab-5");
我也尝试过使用包含域名的完整 URL。
但网站不会重新加载。 URL 只是被替换,并没有跳转到锚点。
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
index.php
<?php
ob_start();
session_name("xxx");
session_start();
include("app/Routes.php");
$template = checkRoute();
// Redirect to login page if user is not logged in
if (!$template && !isset($_SESSION["logged_in"])) {
$bodyClass = "login";
$template = "templates/php/login.php";
// Redirect to start page (list view) if user is logged in and no url is given
} else if (!$template) {
header("Location: /property/list");
exit;
}
// Redirect to template
if (file_exists($template)) {
require_once($_SERVER["DOCUMENT_ROOT"] . "/master.php");
exit;
}
app/Routes.php
<?php
/**
* A .htaccess rule always calls the index.php if a file could not be found.
* This method gets called by index.php and creates a path out of the request
* url path and returns the affiliated template file if exist. If nothing is found,
* then return "no-route" template.
*/
function checkRoute()
{
$redirectUrl = (isset($_SERVER["REDIRECT_URL"])) ? $_SERVER["REDIRECT_URL"] : "";
$_SERVER["REDIRECT_URL"] = "";
if (!empty($redirectUrl) && $redirectUrl !== "/login") {
$templateRoot = "templates";
$template = $templateRoot . "/php". $redirectUrl .".php";
if ( ! file_exists($template)) {
$template = "/". $template;
if ( ! file_exists($template)) {
$template = $templateRoot . "/html/no-route.html";
}
}
if (file_exists($template)) {
return $template;
}
}
if (!empty($_SESSION["logged_in"])) {
return false;
}
}
【问题讨论】:
-
在其他条件相同的情况下,应该可以。
-
@Quentin url-rewrite 会导致这个“问题”吗?
标签: javascript .htaccess