htaccess的URL作为参数 [英] htaccess url as parameter

查看:297
本文介绍了htaccess的URL作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,并在此先感谢,我想添加一个URL作为参数,但我不能。 我的原则是:

  RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
(。*)(。*)?|重写规则^方式/([一 - 杂 -  Z0-9] +)/ / $ info.php的用户= $ 1和2文本= $&安培;网址= $ 3
 

在浏览器中: 的http://本地主机/例子/信息/彼得/喜家伙/ HTTP://www.example.com

返回数组 $ _ GET PHP

  [用户] =>彼得
[文] =>喜的家伙/ HTTP:
[URL] => www.example.com
 

什么是正确的:

  [用户] =>彼得
[文] =>嗨你好
[URL] => http://www.example.com
 

我希望你的帮助,感谢

解决方案

  RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^信息/([A-ZA-Z0-9 |] +)/([^ /] *)/ $ info.php的用户= $ 1安培(*);?文字= $ 2及URL = $ 3 [B ,QSA]
 

[^ /] 表示任何字符,这不是一个斜杠。当然,这意味着,文字不能包含任何斜杠,但你的URL会正确匹配。

另外还要注意的 [B] 这是许多选项,你可以添加到重写规则之一。 [B] 意味着任何&安培; 和其他一些字符转义。所以,如果你是作为一个参数的URL都有查询字符串,它可以在 $ _ GET ['URL'] ,其中它的参数,否则将有兴趣的朋友$读出p $ PTED作为新的查询字符串的一部分。

Hi all and thanks in advance, I'm trying to add a url as a parameter but I can not. My rule is:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^info/([a-zA-Z0-9|]+)/(.*)/(.*)$ info.php?user=$1&text=$2&url=$3

In the browser: http://localhost/example/info/peter/hi guy/http://www.example.com

Return array $_GET php

[user] => peter
[text] => hi guy / http:
[url] => www.example.com

What would be correct:

[user] => peter
[text] => hi guy
[url] => http://www.example.com

I hope your help thanks

解决方案

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^info/([a-zA-Z0-9|]+)/([^/]*)/(.*)$ info.php?user=$1&text=$2&url=$3 [B,QSA]

[^/] means "any character that's not a slash". Naturally this means that "text" cannot contain any slashes, but your URL will be matched correctly.

Also note the [B] which is one of many options you can add to a rewrite rule. [B] means that any &s and some other characters will be escaped. So if the URL that you're as a parameter has a query string, it can be read out in $_GET['url'] where its parameters would otherwise be interepreted as part of the new query string.

这篇关于htaccess的URL作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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