JavaScript不能找到我的mod_rewrite的查询字符串! [英] Javascript can't find my mod_rewrite query string!

查看:126
本文介绍了JavaScript不能找到我的mod_rewrite的查询字符串!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的JavaScript类拔变量了查询字符串:

I use the following javascript class to pull variables out of a query string:

getUrlVars : function() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

所以这部作品 http://example.com/signinup.html?opt=登录

我需要 http://www.example.com/login/ 以相同的方式工作。使用mod_rewrite:

I need http://www.example.com/login/ to work the same way. Using mod_rewrite:

重写规则^登录/? signinup.html?选择=登录[QSA]

允许网页加载,加载的JavaScript,CSS的加载,但我的JavaScript功能无法找到选择键(即,它是未定义)。我如何获得选择来我的JavaScript?

allows the page to load, the javascript to load, the css to load, but my javascript functions can't find the opt key (i.e., it's undefined). How do I get opt to my javascript?

推荐答案

JavaScript是客户端。 mod_rewrite的是服务器端。

Javascript is client-side. Mod_rewrite is server-side.

因此​​JavaScript就永远看不到重写URL。至于你的浏览器而言,您所输入的网址是完成的地址。

Therefore Javascript will never see the rewritten URL. As far as your browser is concerned, the URL that you entered is the finished address.

唯一真正的解决办法是改变你的Javascript所以看它有而不是老版本的URL(或可能解析这两个备选方案,因为旧的网址仍然可以工作,人们可能仍然有旧书签)。

The only real solution is to change your Javascript so it looks at the URL it's got rather than the old version (or possibly parse for both alternatives, since the old URL will still work and people may still have old bookmarks).

其他可能的解决办法是去你的服务器端code(PHP?什么?),在这里你可以看到重写URL,并插入一些JavaScript code那里,你可以在客户端解析侧。虽然不是一个理想的解决方案。你会只是选择1去和改变了你的Javascript,以应付它实际上是会越来越URL的更好。

The other possible solution would be to go to your server-side code (PHP? whatever?) where you can see the rewritten URL, and insert some javascript code there which you can parse on the client side. Not an ideal solution though. You'd be better of just going with option 1 and changing you Javascript to cope with the URLs it's actually going to be getting.

这篇关于JavaScript不能找到我的mod_rewrite的查询字符串!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆