带变量的 htaccess 重定向

发布于 2024-11-19 17:30:29 字数 191 浏览 0 评论 0原文

有人可以帮我解决这个问题吗?我想做的是重定向 -

http://www.domain.com/testpage 

如果

http://www.domain.com/index.php?id=testpage

该页面在服务器上不存在。

Can someone help me with this? What I'm trying to do is redirect -

http://www.domain.com/testpage 

to

http://www.domain.com/index.php?id=testpage

if that page does not exist on server.

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

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

发布评论

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

评论(1

乖乖 2024-11-26 17:30:29

使用 .htaccess 和 RewriteRule

# -f means "is it a file" !-f "not(is it a file)"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/id=$1 [L]
# RewriteRule takes a regular expression and an output followed by
# a set of instructions in the brackets.
# in this case, we're saying, 'take anything not found and add it to index.php?id=
# [L] means that this should be considered a final instruction -- no more rules
# should apply here.

Using .htaccess and RewriteRule

# -f means "is it a file" !-f "not(is it a file)"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/id=$1 [L]
# RewriteRule takes a regular expression and an output followed by
# a set of instructions in the brackets.
# in this case, we're saying, 'take anything not found and add it to index.php?id=
# [L] means that this should be considered a final instruction -- no more rules
# should apply here.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文