Apache Mod_Rewrite 正则表达式帮助

发布于 2024-11-28 03:51:33 字数 683 浏览 6 评论 0原文

我正在尝试修改 URL 和变量,但不确定是否遇到语法错误或只是使用了错误的表达式。

我试图改变这个:

http://www.mydomain.com/trainings/12345

进入这个:

http://www.mydomain.com/remote.php?page=abcde&var=12345

remote.php?page=abcde 是静态的,永远不会改变。因此只需传递该变量并去掉 URL 中的 /trainings 即可。 12345将会改变。

我尝试了以下方法,但没有成功:

    RewriteCond %{QUERY_STRING} /trainings/(.*)
    RewriteRule remote.php?page=abcde remote.php?page=abcde&var=%1 [QSA,L]

我还尝试了上述方法的一些变体,但没有成功。

我很确定我使用了错误的语法。非常感谢任何帮助!

I'm trying to modify a URL and variable, and I'm not sure if I'm running into syntax errors or just using the wrong expressions.

I'm trying to turn this:

http://www.mydomain.com/trainings/12345

into this:

http://www.mydomain.com/remote.php?page=abcde&var=12345

The remote.php?page=abcde is static and will never change. So just need to pass that variable and strip out the /trainings in the URL. The 12345 will change.

I've tried the following with no luck:

    RewriteCond %{QUERY_STRING} /trainings/(.*)
    RewriteRule remote.php?page=abcde remote.php?page=abcde&var=%1 [QSA,L]

I've also tried some variations of the above with no success.

I'm pretty sure I'm using the wrong syntax. Any help is much appreciated!!

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

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

发布评论

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

评论(1

一抹微笑 2024-12-05 03:51:34

这应该有效

Options +FollowSymlinks
RewriteEngine On
RewriteBase /


RewriteRule ^trainings/([^/]+) remote.php?page=abcde&var=$1 [QSA] 

This should work

Options +FollowSymlinks
RewriteEngine On
RewriteBase /


RewriteRule ^trainings/([^/]+) remote.php?page=abcde&var=$1 [QSA] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文