mod_rewrite 从带有查询字符串的子文件夹到文件夹或文件
我正在尝试从: 重定向
http://www.example.com/folder/product.aspx?prodid=146
到
http://www.example.com/folder2/folder3/
此处提到的文件夹实际上并不存在。还有其他重写规则可以透明地重定向到实际内容。
如果我创建一个名为“文件夹”的目录,并在其中放入 .htaccess 文件,我可以使重定向正常工作,但是引用该文件夹的其他 URL 不再工作。所以我必须尝试从 ROOT 文件夹中的 .htaccess 文件进行重定向。
我尝试了这个:
RewriteCond %{QUERY_STRING} prodid=146
RewriteRule ^/folder/product.aspx$ /folder2/folder3/? [R]
...但它不起作用(我收到 404 错误)。如果 .htaccess 位于文件夹目录中,则使用相同的语法但从第二行省略 /folder/ 是可行的(所以我知道上面的内容不会太远) - 但正如我所说,我不能这样做。我尝试了很多变化,但似乎没有任何效果。任何帮助表示赞赏。
I am trying to redirect from:
http://www.example.com/folder/product.aspx?prodid=146
to
http://www.example.com/folder2/folder3/
The folders referred to here don't really exist. There are other rewrite rules in place which redirect transparently to the actual content.
If I create a directory called 'folder', and put an .htaccess file in it, I can get the redirect working, BUT, other URLs which refer to that folder no longer work. So I have to try and do the redirect from the .htaccess file in the ROOT folder.
I tried this:
RewriteCond %{QUERY_STRING} prodid=146
RewriteRule ^/folder/product.aspx$ /folder2/folder3/? [R]
...but it doesn't work (I get a 404 error). Using identical syntax but omitting the /folder/ from the 2nd line works if the .htaccess is in the folder directory (so I know the above can't be too far off) - but as I said, I cannot do that. I have tried lots of variations but nothing seems to work. Any assistance appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要删除 URL 正则表达式开头的斜杠。像这样:
You need to remove the slash from the start your URL regexp. Like this: