我有一个基于PHP的Web应用程序,我正在尝试将Apache的mod_rewrite应用于.
原始网址的格式为:http:
//example.com/index.php?page = home&x = 5
我想将它们转换为:http:
//example.com/home?x = 5
请注意,在重写页面名称时,我也有效地"移动"了问号.当我尝试这样做时,Apache愉快地执行这个翻译:
RewriteRule ^/([a-z]+)\?(.+)$ /index.php?page=$1&$2 [NC,L]
Run Code Online (Sandbox Code Playgroud)
但它弄乱了$_GETPHP中的变量.例如,调用http://example.com/home?x=88只产生一个$_GET变量(page => home).哪x => 88去了?但是,当我将规则更改为使用&符号而不是问号时:
RewriteRule ^/([a-z]+)&(.+)$ /index.php?page=$1&$2 [NC,L]
Run Code Online (Sandbox Code Playgroud)
一个类似的调用就像http://example.com/home&x=88我期望的那样工作(即page和x_GET变量都设置得恰当).
我知道差异很小,但我希望我的URL变量能够"开始"带问号,如果可能的话.我确信这反映了我自己对mod_rewrite重定向如何与PHP交互的误解,但似乎我应该能够做到这一点(这样或那样).
提前致谢!
干杯,
-Chris
嗨,我有这个代码
NSLog(@"%@",URLRequestQueryString);
NSString *sendToServerString = [NSString stringWithFormat:@"http://mydomain.co.uk/req.php%@",URLRequestQueryString];
NSURL *sendToServer = [[NSURL alloc] initWithString:sendToServerString];
NSLog(@"%@",sendToServer);
NSLog(@"%@",sendToServerString);
Run Code Online (Sandbox Code Playgroud)
URLRequestQueryString只是我在整个脚本中构建的标准查询字符串.
第一个NSLog工作正常并输出一个正确的查询字符串(如果我将其复制并粘贴到浏览器中,那么页面将加载并正确运行.
当我输出sendToServerString正确输出带有查询字符串的URL(我也可以将其复制并粘贴到浏览器中)时也是这种情况.
但是sendToServer输出(null).如果我删除查询字符串,它将正确输出域和路径.
知道为什么会这样吗?我怎么排序呢?
谢谢.
我正在使用Apache2和mod_rewrite来隐藏我的查询字符串.这些是有问题的规则.
RewriteCond %{QUERY_STRING} ^query=(.*)$
RewriteRule (.*) /search/%1 [R=301,L]
RewriteRule ^search\/?$ /search/?query=test [R=301,L]
Run Code Online (Sandbox Code Playgroud)
当我访问/search(或/search/)时,我被正确地重定向到/search/?query=test(根据最后的规则)
从那里,RewriteCond而RewriteRule应该踢在和重定向我/search/test,对不对?据我了解了%1我的第一个RewriteRule对应于(.*)在RewriteCond其中应该包含test.
然而,实际发生的是我被重定向到/search/test/?query=test.因此,该规则有效,但由于某种原因附加了查询字符串.QSA选项是以某种方式/某处自动添加的吗?
然后我陷入了一个无限循环的重定向,/search/test?query=test因为第一个RewriteCond又RewriteRule重新启动,再一次又一次......
我究竟做错了什么?!
谢谢!
我有一个文本框输入描述如果我提交需要通过ajax发送并存储在db中.
问题:-
Example text in textbox:- "Hi all & solve my problem"
in the next page i am getting till "Hi all"
Remaining text is missing, If I pass through get or post method using ajax.
Run Code Online (Sandbox Code Playgroud)
给我解决方案.如何获取我放在文本框中的所有内容以及"&"
我刚刚为我正在正常工作的项目添加了一些搜索功能.刚刚使用SO搜索,我意识到有一个小细节,我更喜欢自己的搜索,我很好奇它是如何实现的,因为我也使用MVC 3和Razor为我的网站.
如果我搜索SO,我最终会得到一个URL,例如:
http://stackoverflow.com/search?q=foo
Run Code Online (Sandbox Code Playgroud)
但是,搜索我自己的应用程序会导致:
http://example.com/posts/search/?searchTerms=foo
Run Code Online (Sandbox Code Playgroud)
请注意/之间search和?.虽然这纯粹是装饰性的,但如何从URL中删除它,最终结果如下:
http://example.com/posts/search?searchTerms=foo
Run Code Online (Sandbox Code Playgroud)
这是我的搜索路线:
routes.MapRoute(
"SearchPosts",
"posts/search/{*searchTerms}",
new { controller = "Posts", action = "Search", searchTerms = "" }
);
Run Code Online (Sandbox Code Playgroud)
我试过从路线中删除斜线,但这给出了一个错误.我也尝试添加一个?而不是斜杠,但也出错了.有人会善意为我解决这个谜吗?
将JSON对象转换为查询字符串以附加到GET Url的最佳方法是什么?POST很简单,我的Web API后端会读取它.
{姓名:'迈克'} =?姓名=迈克
private static string MakeRequest(HttpWebRequest req, string data)
{
try
{
if (req.Method == Verbs.POST.ToString() || req.Method == Verbs.PUT.ToString() || req.Method == Verbs.DELETE.ToString())
{
var encodedData = Encoding.UTF8.GetBytes(data);
req.ContentLength = encodedData.Length;
req.ContentType = "application/json";
req.GetRequestStream().Write(encodedData, 0, encodedData.Length);
}
using (var response = req.GetResponse() as HttpWebResponse)
using (var reader = new StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
catch (WebException we)
{
if(we.Response == null)
{
return JsonConvert.SerializeObject(new { Errors = new List<ApiError> { new ApiError(11, "API is …Run Code Online (Sandbox Code Playgroud) 如何使用queryString将值从一个asp.net页面传递到另一个asp.net网页.这意味着test1.aspx和test2.aspx是两个网页.
在test1.aspx中,我有字符串值,
string abc="stackoverflow";
Run Code Online (Sandbox Code Playgroud)
如果我这样使用
Request.Redirect("test2.aspx?numbers ="+ abc); .它不会工作.如果我这样使用,我无法在test2.aspx页面获得abc值.
how to get this abc values into the test2.aspx?
Run Code Online (Sandbox Code Playgroud) asp.net request.querystring query-string querystringparameter c#-4.0
我正在制作一个简单的asp.net应用程序,它显示可以根据几个不同的参数进行过滤的数据.因此,当前选择的不同过滤器需要保存在某处.我是.NET的新手,我想知道保存这些信息的最佳方法.我注意到一位同事将Request.QueryString与Sessions字典结合使用.页面加载时这样的东西:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Category"] != null &&
Request.QueryString["Value"] != null)
{
string Category = Request.QueryString["Category"];
string CategoryValue = Request.QueryString["Value"];
// selectedFacets is the server side dictionary
selectedFacets.Add(Category, CategoryValue);
}
}
Run Code Online (Sandbox Code Playgroud)
当用户按下网页上的按钮更新URL时,会更改此处的QueryString.
我的问题是,为什么在我们使用它时,甚至根本不需要使用QueryString来保存值服务器端呢?不仅仅是让按钮成为asp控制器更容易,例如:
protected void exampleCatexampleVal_Button_onClick(object sender, EventArgs e)
{
selectedFacets.Add(exampleCat, exampleVal);
}
Run Code Online (Sandbox Code Playgroud)
类似的业务继续使用Sessions字典:它只是用于将一堆值保存到服务器上的变量,那么为什么要首先使用它呢?我确信这是有充分理由的,但是现在他们看起来似乎过于复杂.谢谢!
我收到此错误重定向URI不能包含换行符.当运行下面的代码.工作MVC 4.她是我的工作代码.
protected void Application_Error(Object sender, System.EventArgs e)
{
System.Web.HttpContext context = HttpContext.Current;
System.Exception exception = Context.Server.GetLastError();
var stackTraceExcep = new StackTrace(exception, true); // create the stack trace
var stackTrace = stackTraceExcep.GetFrames() // get the frames
.Select(frame => new
{ // get the info
FileName = frame.GetFileName(),
LineNumber = frame.GetFileLineNumber(),
ColumnNumber = frame.GetFileColumnNumber(),
Method = frame.GetMethod(),
Class = frame.GetMethod().DeclaringType,
}).FirstOrDefault();
string FileName = stackTrace.FileName;
string LineNumber = stackTrace.LineNumber;
string ColumnNumber = stackTrace.ColumnNumber;
string MethodName = stackTrace.Method.Name; …Run Code Online (Sandbox Code Playgroud) 第一个块按预期工作
getQuotes(): Observable<Quote[]> {
return this.http.get(this.url)
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}
Run Code Online (Sandbox Code Playgroud)
现在我要向this.url添加查询参数,并且url没有改变
getQuotes2(): Observable<Quote[]> {
let myParams = new URLSearchParams();
myParams.append('author', 'authorName');
myParams.append('catid', '123');
let options = new RequestOptions({ params: myParams });
return this.http.get(this.url, options )
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}
Run Code Online (Sandbox Code Playgroud)
我检查过devtools.缓存已关闭.我尝试{search:myParams},使用RequestOptions并返回this.http.get(this.url,{params:myParams})我不看的地方我看到字符串连接.这些参数是optinal,我将它们附加在条件上.