Mobile app version of vmapp.org
Login or Join
Rambettina238

: How to rewrite %20 in .htaccess I need to perform an equivalent rewrite to: RewriteRule ^/this%20file.pdf http://www.example.com/ How do I handle the %20? I have tried RewriteRule ^/this%20file.pdf

@Rambettina238

Posted in: #ModRewrite #UrlRewriting

I need to perform an equivalent rewrite to:

RewriteRule ^/this%20file.pdf www.example.com/

How do I handle the %20?

I have tried

RewriteRule ^/this%20file.pdf www.example.com/

and

RewriteRule ^/this(s|%20)file.pdf www.example.com/

but these have not worked.

The website is part of a Wordpress network, so it doesn't have it's own directory or subdomain where I can place a .htaccess file containing redirects; it's a virtual subdomain with domain mapping. So, the Wordpress .htaccess rewriterule is preceeded by

RewriteCond %{HTTP_HOST} ^example.com$ [NC]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Rambettina238

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sims2060225

You shouldn't need to use percent encoding/hexcode in mod_rewrite parameters since mod_rewrite will encode special characters (?, #, , &, etc.) by default. To write a space in the rewrite pattern, use s or just escape the space with a backslash (). Whether space gets encoded as %20 or + depends on whether it's part of the query string or the URI.

So your rule should look like this:

RewriteRule ^/this file.pdf www.example.com/

Or:

RewriteRule ^/thissfile.pdf www.example.com/

If you do want to manually specify the URI encoding, then you need to use the NE (noescape) flag to tell mod_rewrite not to escape special characters.

Otherwise, /this%20file.pdf gets treated as /this%2520file.pdf, as the % will be encoded as %25.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme