简体   繁体   English

.htaccess棘手网址的重写规则

[英].htaccess rewrite rule for tricky url

I haven't touched .htaccess for years since switching over to nginx, but I have this site using good ol' Apache. 自切换到nginx以来,我已经有好几年没有碰过.htaccess了,但是我使用的是很好的Apache网站。 I need to rewrite it's rather unorthodox URL (due to AJAX) to a clean one. 我需要将其相当非传统的URL(由于AJAX)重写为一个干净的URL。

It currently looks like this: 当前看起来像这样:

site.com/#!products/desserts/35/carrot-cake/ 

But preferably I want it to read.. 但最好是我希望它能阅读。

site.com/products/desserts/carrot-cake

With that said, what's the simplest way of taking away the #! 这么说,带走#号最简单的方法是什么 and /35/ in this? / 35 /中? The number 35 represents the ID of the product, but that could be catched via it's alias carrot-cake anyway. 数字35代表产品的ID,但无论如何都可以通过别名胡萝卜蛋糕来捕获。

I tried using the rewrite generators out there, but it seems they have a hard time grabbing this kind of URL. 我尝试使用那里的重写生成器,但似乎它们很难抓住这种URL。

Nothing you can do in htaccess here. 您在这里无法在htaccess中做任何事情。 Everything after the # is the URL Fragment, and that's never sent to the server. #后面的所有内容都是URL片段,并且永远不会发送到服务器。

So when the browser goes to: site.com/#!products/desserts/35/carrot-cake/ , the only thing apache sees is a request for / , which means there's nothing you can do in htaccess that can change the fragment. 因此,当浏览器转到: site.com/#!products/desserts/35/carrot-cake/ / ,apache唯一看到的是对/的请求,这意味着您在htaccess中无法做任何更改片段的操作。

You'll need to do something on the client side if you want to make the URL look differently. 如果要使URL看起来与众不同,则需要在客户端进行一些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM