重写URL以包含一个带有空格的额外参数

时间:2016-12-30 14:37:45

标签: apache .htaccess mod-rewrite url-rewriting

现在.htaccess rewrites all URLs and includes a parameter,该参数如何在其中留出空格?

例如

虽然%20testing in a .htaccess simulator时有效,但它在我的DreamHost帐户中无效。

1 个答案:

答案 0 :(得分:0)

你是对的;即使添加%20在模拟器中工作,它也无法在真正的httpd服务器上运行。

要添加空格,您需要使用\转义它。这是你的htaccess文件的样子:

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]

pa=v\ a指令中注意RewriteRule