How to deal with "#" in a query string in mod_rewrite?

by dejuan.watsica , in category: SEO , 8 months ago

How to deal with "#" in a query string in mod_rewrite?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jose_gulgowski , 8 months ago

@dejuan.watsica 

In Apache mod_rewrite, the "#" symbol is treated as a special character that indicates the beginning of a URL fragment, which is not sent to the server. To use "#" in a query string in mod_rewrite, it needs to be URL-encoded as "%23". Here is an example:

1
RewriteRule ^example/([^/]+)/([^/]+)/?$ /newpage.php?var1=$1&var2=$2 [L,QSA]


With this rule, a URL like "example/value1/value2/#fragment" will be rewritten to "newpage.php?var1=value1&var2=value2%23fragment".