htaccess 缩短 url
我想缩短
www.site.com/product/info/laptop 至 www.site.com/laptop
我使用了
RewriteRule ^(.+)$ /product/info/$1
收到 500 内部服务器错误
但当我尝试时
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()_=&-]+)$ /product/info/$1
,它有效,但我也想支持该期间,所以当我包含 .
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()\._=&-]+)$ /product/info/$1
它给了我 500 Internal Server Error
你能解释一下发生了什么吗?
谢谢
i would like to shorten
www.site.com/product/info/laptop to www.site.com/laptop
I used
RewriteRule ^(.+)$ /product/info/$1
but i get 500 Internal Server Error
when i try,
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()_=&-]+)$ /product/info/$1
it works but i want to support the period as well, so when I include .
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()\._=&-]+)$ /product/info/$1
It gives me 500 Internal Server Error
Could you explain what is going on?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下操作:
这会将浏览器从 www.example.com/product/info/laptop 重定向到 www.example.com/laptop,并带有“永久移动”标头。
如果您希望较短的 URL 在内部指向较长的 URL,则必须避免循环重定向:
第一行将停止尝试将 www.example.com/product/info/laptop 重定向到 www.example.com/product /info/product/info/laptop 等。
编辑
根据您的评论,看起来您还试图将除 img、phpmyadmin 等之外的所有内容重定向到索引?无论如何 - 您现在必须重新排列一下,如下所示:
我并不是 100% 同意第一次重写的“product/info/(.*)”部分。如果这不起作用,请尝试以下操作:
编辑 2
根据您的评论的最终答案:
Try the following:
That will redirect the browser from www.example.com/product/info/laptop to www.example.com/laptop with a "Moved Permanently" header.
If you mean you wish the shorter URL to point to the longer URL internally, then you must avoid circular redirections:
The first line will stop trying to redirect www.example.com/product/info/laptop to www.example.com/product/info/product/info/laptop, and so-on.
Edit
Based on your comment, it looks like you're also trying to redirect everything except img, phpmyadmin, etc, to index?whatever - You have to rearrange it all a bit now, something like this:
I'm not 100% on the "product/info/(.*)" part of the first rewrite. If that doesn't work, try this:
Edit 2
Final answer based on your comment: