.htaccess 将规则从 http://example.com/~something/blabla 重写为 http://example.com/blablabla

发布于 2024-09-26 09:18:25 字数 547 浏览 1 评论 0原文

.htaccess 重写规则的小问题.. 我想像这样重定向http请求:

http://example.com/~something /blabla/blablabla?blabla=blabla

作为这样的请求:

http:// example.com/blabla/blablabla?blabla=blabla

只需删除 ~something (可以是其他任何东西,但开头带有 ~ ......)

我已经尝试过这段代码,但根本不起作用......:

RewriteEngine on
RewriteRule ~something/(.*) $1 [P,L]

Little question with .htaccess rewrite rule..
I want to redirect http request like that:

http://example.com/~something/blabla/blablabla?blabla=blabla

as an request like that:

http://example.com/blabla/blablabla?blabla=blabla

Simply remove the ~something (with can be anything else but with an ~ at beginning...)

I have tried this code but not working at all...:

RewriteEngine on
RewriteRule ~something/(.*) $1 [P,L]

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

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

发布评论

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

评论(1

眉目亦如画i 2024-10-03 09:18:25

沿着这些路线的东西应该可以工作(这假设使用 .htaccess 文件,IIRC,如果您在 Apache 配置文件中执行此操作,则需要在 RewriteRule 指令中添加前导斜杠):

RewriteEngine On
RewriteRule ~[^/]*/(.*) http://domain.com/$1 [R]

无论哪种方式,RewriteLog 和RewriteLogLevel 指令(请参阅 http://httpd.apache.org/docs/current/mod /mod_rewrite.html)是你在这里的朋友。

Something along these lines should work (this assumes use of a .htaccess file, IIRC you'll need to add a leading slash to the RewriteRule directive if you're doing this in your Apache config file instead):

RewriteEngine On
RewriteRule ~[^/]*/(.*) http://domain.com/$1 [R]

Either way, the RewriteLog and RewriteLogLevel directives (see http://httpd.apache.org/docs/current/mod/mod_rewrite.html) are your friends here.

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