Mod_Rewrite:将普通 /url 转换为 /#!/url

发布于 2024-12-25 16:07:29 字数 478 浏览 2 评论 0 原文

我有以下两种网址情况...

  1. http://url.com/one
  2. http://url.com/category/some

如果这些 url 被调用,我希望 mod_rewrite 调用...

  1. http://url.com/#!/one
  2. http: //url.com/#!/category/some

我该怎么做?

I have the following two url cases …

  1. http://url.com/one
  2. http://url.com/category/some

If those urls are called I want mod_rewrite to call …

  1. http://url.com/#!/one
  2. http://url.com/#!/category/some

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2025-01-01 16:07:29

像这样的东西吗?

# not existing file (images, css, etc)
RewriteCond %{REQUEST_FILENAME} !-f
# no query parameters
RewriteCond %{QUERY_STRING} =""
# not /
RewriteCond %{REQUEST_URI} !^/$
# external redirect and pass along query string and uri as fragment
# i guess this must be an external redirect as the server side should
# not see the fragment, R=redirect, NE=dont escape #, L=last rule
RewriteRule ^(.*)$ /#!/$1 [R,NE,L]

# same but with query parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /?%{QUERY_STRING}#!/$1 [R,NE,L]  

但我不确定这是否是个好主意。也许您应该在应用程序逻辑中或使用客户端脚本进行重定向。

Something like this?

# not existing file (images, css, etc)
RewriteCond %{REQUEST_FILENAME} !-f
# no query parameters
RewriteCond %{QUERY_STRING} =""
# not /
RewriteCond %{REQUEST_URI} !^/$
# external redirect and pass along query string and uri as fragment
# i guess this must be an external redirect as the server side should
# not see the fragment, R=redirect, NE=dont escape #, L=last rule
RewriteRule ^(.*)$ /#!/$1 [R,NE,L]

# same but with query parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /?%{QUERY_STRING}#!/$1 [R,NE,L]  

But im not sure if this is good idea. Maybe you should do the redirect in application logic or with a client side script instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文