htaccess 301 重定向与 mod_rewrite

发布于 2024-12-29 20:19:15 字数 653 浏览 1 评论 0原文

我看到了 htaccess 示例和生成器的负载来重写 url,但是我需要为一个 Web 应用程序放入 301 重定向,该应用程序曾经位于子域上,但现在位于目录中,它也从 .asp tp .php 移动

基本重定向是

http://sub.domain.com/twforum/forum.asp?FORUM_ID= 

重定向到

http://domain.com/forum/viewforum.php?f=

我可以做的这部分,但我不知道如何处理将在网址中传递的 id(论坛 id),我不希望论坛 id 被重写为url 友好打开,只是为了将其转移/重定向

我假设我需要 mod_rewrite 查询部分。

这就是我得到的,

RewriteEngine On
RewriteCond %{QUERY_STRING} ^http://sub.domain.com/twforum/forum.asp?FORUM_ID=1$ [NC]
RewriteRule http://domain.com/forum/viewforum.php\?f=1$ [L,R=301]

任何人都可以看到那里有任何明显的错误或知道更好的方法吗?

谢谢

Iv seen load of htaccess examples and generators to rewrite a url, however I need to put in a 301 redirect for a web app which used to be on a subdomain, but is now in a directory, its also moved from .asp tp .php

the basic redirect is

http://sub.domain.com/twforum/forum.asp?FORUM_ID= 

redirects to

http://domain.com/forum/viewforum.php?f=

this part i can do, but i dont know how to handle the id (forum id) that will be passed in the url, I DONT want the forum id to be rewritten to a url friendly on, just for it to be carried over/redirected

I assume i need to mod_rewrite the query part.

heres what iv got

RewriteEngine On
RewriteCond %{QUERY_STRING} ^http://sub.domain.com/twforum/forum.asp?FORUM_ID=1$ [NC]
RewriteRule http://domain.com/forum/viewforum.php\?f=1$ [L,R=301]

can anyone see any clear errors there or know of a better way?

thanks

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

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

发布评论

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

评论(1

人生戏 2025-01-05 20:19:15

%{QUERY_STRING} 不包含整个网址。只是查询设置部分。例如 FORUM_ID=1

假设您的论坛 ID 只是数字。

RewriteEngine On
RewriteCond %{QUERY_STRING} FORUM_ID=(\d+)$ [NC]
RewriteRule ^ http://domain.com/forum/viewforum.php\?f=%1$ [L,R=301]

%{QUERY_STRING} does not contain the whole of the URL. Just the query setting part. e.g. FORUM_ID=1

Assuming that your fourum ids re just numerals.

RewriteEngine On
RewriteCond %{QUERY_STRING} FORUM_ID=(\d+)$ [NC]
RewriteRule ^ http://domain.com/forum/viewforum.php\?f=%1$ [L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文