Jquery window.location.replace,仅重定向到基本 URL

发布于 2024-12-13 16:48:17 字数 1056 浏览 2 评论 0原文

我使用 .htaccess(mod 重写)来获得漂亮的 SEO 友好 URL。我有一个表格,用户可以在其中更改他/她的帐户密码。我使用 Jquery 向用户提供他/她的密码已更改的信息,并在 3 秒内将页面重定向到登录页面。

setTimeout(function() {window.location.replace("http://localhost/projects/v4/login/#login");} , 3000);

由于某种原因,此代码重定向到 http://localhost/projects/v4/#login 而不是 http://localhost/projects/v4/login/#login。我在问题的开头提到了 SEO 友好的 URL。我开始认为出现这个问题是因为我在 元素之间使用基本 URL。

<base href="http://localhost/projects/v4/" />

这个问题有什么解决方案吗?还是我弄错了,这个问题是由于一些完全不同的问题而发生的?

.htaccess

<IfModule mod_rewrite.c>

Options +FollowSymlinks
RewriteEngine on

RewriteBase /projects/v4/

RewriteRule ^index/ index.php [L]

# MEMBERS
ReWriteRule ^login/(.*) ?module=login&a=$1 [L]

# MODULES
RewriteRule ^([^/\.]+)$ ?module=$1 [L]

# LAST ONES
#RewriteCond %{THE_REQUEST} \?(ref=.*)?\ HTTP [NC]
#RewriteRule .? http://localhost/projects/v4%{REQUEST_URI}? [R=301,L]

</IfModule>

感谢您的时间和关心。

I'm using .htaccess (mod rewrite) to have pretty looking SEO friendly URLs. I have a form where user could change his / her account's password. I provide information with Jquery to the user that his / her password has changed and in 3 seconds page will be redirected to login page.

setTimeout(function() {window.location.replace("http://localhost/projects/v4/login/#login");} , 3000);

For some reason this code redirects to http://localhost/projects/v4/#login instead of http://localhost/projects/v4/login/#login. I mentioned about SEO friendly URLs in the begining of my question. I started to think this problem occurs because I am using base URL between <head></head> element.

<base href="http://localhost/projects/v4/" />

Is there any solution for this problem or am I mistaken and this problem occurs because of some totally different problem?

.htaccess

<IfModule mod_rewrite.c>

Options +FollowSymlinks
RewriteEngine on

RewriteBase /projects/v4/

RewriteRule ^index/ index.php [L]

# MEMBERS
ReWriteRule ^login/(.*) ?module=login&a=$1 [L]

# MODULES
RewriteRule ^([^/\.]+)$ ?module=$1 [L]

# LAST ONES
#RewriteCond %{THE_REQUEST} \?(ref=.*)?\ HTTP [NC]
#RewriteRule .? http://localhost/projects/v4%{REQUEST_URI}? [R=301,L]

</IfModule>

Thank you for your time and concern.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆之渊 2024-12-20 16:48:17

您的问题不是由 JavaScript 引起的,而是由您的 .htaccess 文件引起的。确保您的规则正确且不冲突。

[R=301,L] 规则应该放在最后,因为它匹配 v4 中的每个 URL,包括登录。另外,交换 MODULESMEMBERS,因为模块规则也与成员规则匹配。

# MEMBERS
ReWriteRule ^login/(.*)/ ?module=login&a=$1 [L]

# MODULER
RewriteRule ^([^/\.]+)/?$ ?module=$1 [L]
RewriteRule .? http://localhost/projects/v4%{REQUEST_URI}? [R=301,L]

You issue is not caused by JavaScript, but by your .htaccess file. Make sure that your rules are correct, and not conflicting.

The [R=301,L] rule should be last, because it matches every URL at v4, including login. Also, swap MODULES and MEMBERS, because the module rule also matches the member rule.

# MEMBERS
ReWriteRule ^login/(.*)/ ?module=login&a=$1 [L]

# MODULER
RewriteRule ^([^/\.]+)/?$ ?module=$1 [L]
RewriteRule .? http://localhost/projects/v4%{REQUEST_URI}? [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文