无法允许URL这些字符: - %/ \#+ [英] Unable to allow these characters in URL:- % / \ # +

查看:214
本文介绍了无法允许URL这些字符: - %/ \#+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于系统

我在我的项目格式的网址: -

<$p$p><$c$c>http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

其中,关键字/班对指搜索与阶级的关键字。

以下是我的htaccess文件: -

  ## AddHandler的应用程序/ x-的httpd-PHP5的.php

选项​​包括+ ExecCGI
选项​​+的FollowSymLinks

&LT; IfModule mod_rewrite.c&GT;
RewriteEngine叙述上

############要从URL删除的index.php

的RewriteCond $ l ^(指数\ .PHP |资源|机器人\ .TXT)!
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L,QSA]
#################################################结束对发现​​的一类


&LT; / IfModule&GT;
 

我有执行的项目中的每个模块一个共同的index.php文件。 只有一个重写规则,以删除网址的index.php文件(你可以在上面看到)。

我没有使用任何htaccess的重写规则定义的$ _GET数组。我在PHP中的URL解析函数内该做的吧。因为我给的例子URL,解析器返回: -

 阵列([A] =&GT; browse_by_exam【类型】=&GT; tutor_search [关键词] =&GT;类[new_search] =&GT; 1 [search_exam] =&GT; 0 sea​​rch_subject] =&0)
 

我使用urlen code(),而preparing搜索网址和urlde code(),而读搜索URL

问题

我对着在URL中出现问题的某些字符

 字符响应
%400  - 错误的请求 - 您的浏览器发送一个请求,该服务器无法理解。
/                       404未找​​到
\#+页面不破,但urlde code()删除这些字符。
 

我希望让所有这些字符。  可能是什么问题?我该如何让这些? 请帮忙 谢谢, Sandeepan

更新

现在只/字符是造成破URL(404错误像以前一样)。所以,我想通过去除htaccess的重写规则,它可以隐藏的index.php在URL中,并试图用完整的URL来代替。对于一个搜索词类/新我试着用以下两个网址: -

<$p$p><$c$c>http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0 http://project_name/index.php/browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0

和第一个工作,但第二个一个没有。注意的index.php?browse_by_exam 中的第一个。

但我不能用第一URL约定。我必须做出/工作,index.php文件隐藏。请帮忙

再次

谢谢 Sandeepan

修改(解决)

考虑Bobince的答案,我的其他问题

<一个href="http://stackoverflow.com/questions/3235219/urlen$c$cd-forward-slash-is-breaking-url">http://stackoverflow.com/questions/3235219/urlen$c$cd-forward-slash-is-breaking-url ,我觉得这是最好能有这样的网址: - 的http:// PROJECT_NAME / browse_by_exam型/ tutor_search /关键字/班 %2Fnew / new_search / 1 / search_exam / 0 / search_subject / 0

这样,通过我摆脱造成可读性的难度&放大器;参数1 =值1&放大器;参数2 =值2 约定,也能够允许正斜杠的查询字符串的一部分通过使用

我想避免AllowEn codedSlashes因为Bobince说还有一些工具或蜘蛛可能被它混淆。虽然%2F为指/路径中的部分是正确的,因为根据标准,最多卷材的避免它。

解决方案

有些问题听起来像他们都跟你想使用 PATH_INFO (你的重写规则坚持背后一切的index.php ,就好像它是一个路径)。是否有可能只使用了 $ _ SERVER ['REQUEST_URI'] 变量作为输入您的网址解析功能呢?它包含了相同的信息,我觉得这将不是什么大问题。

试图创建一个 PATH_INFO 解决方案似乎并没有很好地工作在每个目录(的.htaccess )上下文。您可以设置 AllowPathInfo在,但一旦的mod_rewrite 试图在内部重定向的URL,它似乎像Apache不希望解析出的网址,这导致404错误的后沿部分

如果您使用 $ _ SERVER ['REQUEST_URI'] 而不是,那么你可以重写的index.php 没有尾随的信息,例如:

 的RewriteCond $ l ^(指数\ .PHP |资源|机器人\ .TXT)!
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php [L,QSA]
 

至于400错误的推移,你的应该是连接codeD为%25 通过 urlen code(),但它听起来像是无论出于何种原因有可能是一个问题。我检查,以确保您的搜索网址确实是正确的连接$ C $光盘发送给浏览器的输出,因为这可能涉及与其他剩余的字符和问题(但我不知道)

编辑:如果您使用上述rerwite,你就必须像

网址 <$p$p><$c$c>http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

,他们将在内部被重定向到的index.php 。然后,你可以得到的部分

<$p$p><$c$c>/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

$ _ SERVER ['REQUEST_URI'] 在脚本(它将包含此值),然后你可以分析像你现在这样。我不知道为什么你要能后有它改写了的index.php ,因为你可以得到这样的信息,即使它不是,它看起来完全相同的在其浏览器的用户。你甚至可以做到这一点在脚本的开头,若部分使用 $ _ SERVER ['PATH_INFO'] 不适用于改变:

  $ _ SERVER ['PATH_INFO'] = $ _ SERVER ['REQUEST_URI'];
 

如果你真的不能像这样做,我不知道,有一个解决方案(有在你的另一个问题,为什么这是有问题的解释),但我会看看,看看它在所有可能的和送还给你。

About the system

I have URLs of this format in my project:-

http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

Where keyword/class pair means search with "class" keyword.

Following is my htaccess file:-

##AddHandler application/x-httpd-php5 .php

Options Includes +ExecCGI
Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine on

############To remove index.php from URL

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
#################################################end of find a class 


</IfModule>

I have a common index.php file which executes for every module in the project. There is only a rewrite rule to remove the index.php from URL (as you can see above).

I am not using any htaccess rewrite rules for defining the $_GET array. I have a URL parser function in PHP inside which does that instead. For the example URL I gave, the parser returns:-

Array ( [a] => browse_by_exam [type] => tutor_search [keyword] => class [new_search] => 1 [search_exam] => 0 [search_subject] => 0 )

I am using urlencode() while preparing the search URL and urldecode() while reading the search URL

Problem

I am facing problems with some characters in the URL

Character               Response
%                       400 - Bad Request - Your browser sent a request that this server could not understand.
/                       404 - Not FOund
\ # +                   Page does not break but urldecode() removes these characters.

I want to allow all these characters. What could be the problem? How do I allow these? Please help Thanks, Sandeepan

Updates

Now only / character is causing URL breaking (404 error like before). So, I tried by removing the htaccess rewrite rule which hides the index.php in the URL and tried with complete URL instead. For a search term class/new I tried with the following two URLs:-

http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0

http://project_name/index.php/browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0

And the first one works but the 2nd one does not. Notice the index.php?browse_by_exam in the first one.

But I cant use the 1st URL convention. I have to make / work with index.php hidden. Please help

Thanks again Sandeepan

Edit (Solved)

Considering Bobince's answer to my other question

http://stackoverflow.com/questions/3235219/urlencoded-forward-slash-is-breaking-url , I feel it is best to have URLs like this:- http://project_name/browse_by_exam?type/tutor_search/keyword/class %2Fnew/new_search/1/search_exam/0/search_subject/0

That way I get rid of the difficulty of readability caused by &param1=value1&param2=value2 convention and also able to allow forward slashes in the query string part by using ?

I want to avoid AllowEncodedSlashes because Bobince said Also some tools or spiders might get confused by it. Although %2F to mean / in a path part is correct as per the standard, most of the web avoids it.

解决方案

Some of the issues sound like they are related to you trying to use PATH_INFO (your RewriteRule sticks everything behind index.php as if it were a path). Would it be possible to just use the $_SERVER['REQUEST_URI'] variable as the input to your URL parser function instead? It contains the same information, and I feel it would be less problematic.

Attempting to create a PATH_INFO solution doesn't seem to work very well in a per-dir (.htaccess) context. You can set AllowPathInfo On, but once mod_rewrite attempts to redirect the URL internally, it seems like Apache doesn't want to parse out the trailing part of the URL, which results in the 404 error.

If you use $_SERVER['REQUEST_URI'] instead, then you can just rewrite to index.php without the trailing information, like so:

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

As far as the 400 error goes, your % should be encoded as %25 by urlencode(), but it sounds like for whatever reason there might be an issue. I'd check to make sure that your search URLs are indeed being properly encoded in the output sent to the browser, as this may be related to issues with the other remaining characters as well (but I'm not sure).

Edit: If you used the rerwite above, you'd have URLs like

http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

and they would be internally redirected to index.php. Then, you could get the part

/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0

from $_SERVER['REQUEST_URI'] in that script (it would contain this value) which you could then parse like you're doing now. I'm not sure why you have to be able to have it rewritten after the index.php, since you can get this information even if it isn't, and it looks the exact same to the user in their browser. You could even do this at the beginning of the script, if the part that uses $_SERVER['PATH_INFO'] is not available for changing:

$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];

If you really can't do it like this, I'm not sure that there is a solution (there was an explanation in your other question on why this is problematic), but I'll look to see if it's at all possible and get back to you.

这篇关于无法允许URL这些字符: - %/ \#+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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