使用 mod rewrite 取消混淆 URL
我在一家公司工作,该公司过去对文章的 URL 进行混淆,需要注册才能使用。所以他们会有类似
/story.php?story_id=Z_ZXYZ
的东西,其中有一些代码将字母映射到数字以计算出真实的故事 ID
等
Z = 0
Y = 1
X = 2
。
我们现在正在移动技术堆栈,并决定不需要混淆的 url。所以我正在考虑是否可以使用 mod rewrite 来混淆 URL
到目前为止,我
RewriteCond %{REQUEST_URI} ^.*story.php [NC]
RewriteCond %{QUERY_STRING} ^.*story_id=Z_([ZXYWVUTSRQ]*) [NC]
RewriteRule ^.*$ /story/${decryptmap:%1} [L,R=301]
在 httpd.conf 文件中有一个重写映射,
<IfModule mod_rewrite.c>
RewriteMap decryptmap txt:decyrpsdstxt
</IfModule>
其中包含内容
##
## decrypt urls
##
Z 0
X 1
等..
但它似乎不起作用,即使我在重写规则中添加了一些文本 RewriteRule ^.*$ /story/${decryptmap:ZXY} [L,R=301]
我得到一个像 /story/?story_id 这样的网址=Z_ZAD
我有什么明显做错的地方吗?我可以看到这两个条件正在匹配,但地图似乎不起作用。
我是否应该尝试让 mod 重写来做到这一点?我可以重定向到一个脚本,该脚本相当容易地完成此操作,但这会将重定向代码放在我不喜欢的两个地方。
(我不担心?story_id=Z_ZAD,我知道如何摆脱它)
I work for a company that used to have a polocy of obfuscating URLs for articles which you needed to register to use. So they would have something like
/story.php?story_id=Z_ZXYZ
which there was some code which mapped letters to numbers to work out the true story id
so
Z = 0
Y = 1
X = 2
etc.
We are now moving technology stack and have decided that obfuscated urls are not needed. So I am looking at whether it is possible to un obfuscate the URLs using mod rewrite
So far I have
RewriteCond %{REQUEST_URI} ^.*story.php [NC]
RewriteCond %{QUERY_STRING} ^.*story_id=Z_([ZXYWVUTSRQ]*) [NC]
RewriteRule ^.*$ /story/${decryptmap:%1} [L,R=301]
I have a rewrite map in the httpd.conf file
<IfModule mod_rewrite.c>
RewriteMap decryptmap txt:decyrpsdstxt
</IfModule>
Which has content
##
## decrypt urls
##
Z 0
X 1
etc..
but it dosn't seem to be working, even if I put some text in the Rewriterule as so RewriteRule ^.*$ /story/${decryptmap:ZXY} [L,R=301]
I get a url like /story/?story_id=Z_ZAD
Is there anything obvious I am doing wrong? I can see that the two conditions are being matched but the map doesn’t seem to work.
Should I even be trying to get mod rewrite to do this? I could redirect to a script which did this fairly easily but that would put redirect code in two places which I didn't like the idea of.
(I'm not worried about the ?story_id=Z_ZAD, I know how to get rid of that)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重写映射将处理已传递的整个字符串。因此,在您的情况下,您一次只需要传递一个字符:
A rewrite map would work with the whole string that has been passed. So in your case you would need to pass just one character at a time: