Pergunta

I have an old url of the form: http://example.com/foo.php?title=foobar#9. The person who constructed the url did not mean for the sharp character to be an actual anchor to the page, it is a special character within the title param value; title IS actually 'foobar#9'.

Now I need to create a rewrite rule. Using the following:

RewriteCond %{query_string} ^title=foobar#9$
RewriteRule  ^/foo.php$ http://example.com/test?  [R=301,L]

the condition is never matched. Using the following

RewriteCond %{query_string} ^title=foobar%239$
RewriteRule  ^/foo.php$ http://example.com/test?  [R=301,L]

the condition is only matched when the url is actually encoded (http://example.com/foo.php?title=foobar%239). Is there any way I can achieve that a user clicks on the (non-encoded) url http://example.com/foo.php?title=foobar#9 link and the condition is matched (and the rewrite rule takes effect)?

Foi útil?

Solução

I'm not sure this can work. The # is something that is usually interpreted only by browsers.

The browser doesn't actually send this character to the webserver (unless encoded) so your rule won't ever match.

This was the log line I saw when trying:

127.0.0.1 - - [15/Apr/2014] "GET /?title=foobar HTTP/1.1" 200 466 "-"

Note that the #9 is missing from the request altogether.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top