Jquery window.location.replace,仅重定向到基本 URL
我使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题不是由 JavaScript 引起的,而是由您的
.htaccess
文件引起的。确保您的规则正确且不冲突。[R=301,L]
规则应该放在最后,因为它匹配v4
中的每个 URL,包括登录。另外,交换MODULES
和MEMBERS
,因为模块规则也与成员规则匹配。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 atv4
, including login. Also, swapMODULES
andMEMBERS
, because the module rule also matches the member rule.