如何首先重定向,然后使用 mod_rewrite 重写

发布于 2024-09-10 06:22:27 字数 594 浏览 3 评论 0原文

我有两个域指向同一主机,例如 example1.com 和 example2.com。

我已经有一个重定向:

RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1 [L]

来捕获诸如 example1.com/hello-world/ => 之类的内容example.com/page.php?q=hello-world

现在我需要满足 3 个特定条件:

1) example1.com/special/ => example2.com/special/ [仅适用于“特殊”]
2) example2.com/ =>; example2.com/special/
3) example2.com/anything-not-special/ => example1.com/anything-not-special/

我可以实现这种情况,只是我希望将右侧栏中的内容显示在 URL 栏中。相反,我得到: example2.com/special/ => example1.com/page.php?q=special

这对我来说并不理想。

任何帮助表示感谢,谢谢!

I have two domains pointing to the same host, say example1.com and example2.com.

I already have a redirect:

RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1 [L]

to catch things like example1.com/hello-world/ => example.com/page.php?q=hello-world

Now I need 3 specific conditions to be met:

1) example1.com/special/ => example2.com/special/ [ONLY for "special"]
2) example2.com/ => example2.com/special/
3) example2.com/anything-not-special/ => example1.com/anything-not-special/

I can get this to happen, except that I want exactly what's in the right-hand column here to be displayed in the URL bar. Instead, I'm getting:
example2.com/special/ => example1.com/page.php?q=special

which is not ideal for me.

Any help appreciated, thanks!

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

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

发布评论

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

评论(1

魂牵梦绕锁你心扉 2024-09-17 06:22:27

看看这是否符合您的要求:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example1.com/special/ [OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example2.com/
RewriteRule ^.*$ http://example2.com/special/ [R=301,L]

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}    =example2.com
RewriteCond %{REQUEST_URI} !=/special/
RewriteRule ^.*$ http://example1.com%{REQUEST_URI} [R=301,L]

RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1

See if this does what you want:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example1.com/special/ [OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example2.com/
RewriteRule ^.*$ http://example2.com/special/ [R=301,L]

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}    =example2.com
RewriteCond %{REQUEST_URI} !=/special/
RewriteRule ^.*$ http://example1.com%{REQUEST_URI} [R=301,L]

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