How to deal with “#” in a query string in mod_rewrite?

狂风中的少年 提交于 2019-12-31 04:31:07

问题


I asked this question about rewriting old "ugly" links into seo friendly ones.

I need to "extract" some information after the "sharp" symbol in some urls. I've created a regular expression to it but it can't seen to work.

After my question, I created this logic for this url for example, script.php?mode=full&id=23:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /script\.php\?mode=full&id=([0-9]+)\ HTTP/
RewriteRule ^script\.php$ fix_old_urls.php?phpfile=script2&id=%1 [NC,L]

But I'm working in a legacy application, and I need to extract the value after the sharp symbol in some pages, in the example url script.php?mode=full#23:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /script\.php\?mode=list\#([0-9]+)\ HTTP/
RewriteRule ^script\.php$ fix_old_urls.php?phpfile=script&id=%1 [NC,L]

(in fix_old_urls I properly redirect with a 301 code).

The first one works, but not the second. To me it looks like it`s the same logic in both. What am I'm doing wrong?


回答1:


Anchor information (the part starting with the #) is never actually sent to the server. It's handled completely by the browser, and thus you can't touch it with mod_rewrite (nor can you access it via server-side scripting languages). The only things that can see it are the browser and client-side scripts (like Javascript).



来源:https://stackoverflow.com/questions/1665200/how-to-deal-with-in-a-query-string-in-mod-rewrite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!