且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重写URL以在其中包含空格的额外参数

更新时间:2023-11-27 12:00:46

您是对的;即使添加%20在模拟器中也可以使用,但在实际的httpd服务器上则不起作用.

You're right; Even though adding %20 works in the simulator, it does not work on a real httpd server.

要添加空格,您需要使用\对其进行转义.这是您的htaccess文件的样子:

To add a space, you need to escape it with a \. Here's what your htaccess file looks like:

RewriteEngine on
RewriteBase /

# Check if the host matches old.io,
# You might want to add www\. to that.
RewriteCond %{HTTP_HOST} ^old\.io

# Rewrite URLs with empty querystring
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://new.com/$1?pa=v\ a [L,R]

# Rewrite URLs with non-empty querystring    
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(.*)$ http://new.com/$1?pa=v\ a&%{QUERY_STRING} [L,R]

注意RewriteRule指令中的pa=v\ a.