问题
Now that .htaccess rewrites all URLs and includes a parameter, how can that parameter have a space in it?
For example
- http://old.io --> http://new.com?pa=v%20a
While %20
works when testing in a .htaccess simulator, it doesn't work on my DreamHost account.
- http://new.com?pa=v%20a --> http://new.com?pa=v0a
- http://new.com?pa=v\ a --> http://new.com?pa=v a
- http://new.com?pa=v%2520a --> http://new.com?pa=v520a
- adding the NE flag doesn't change anything
回答1:
You're right; Even though adding %20
works in the simulator, it does not work on a real httpd server.
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]
Notice pa=v\ a
in RewriteRule
directives.
来源:https://stackoverflow.com/questions/41397961/rewrite-a-url-to-include-an-extra-parameter-with-a-space-in-it