试图让 mod_rewrite 工作

发布于 2024-10-19 22:47:36 字数 792 浏览 3 评论 0原文

我在将 CMS 从旧的 CMS 切换到新的 CMS 时遇到了这个问题,因此我尝试正确重定向 url。

以下是我想要转换的一些示例网址:

#-1) http://www.mysite.com/?dispatch=search_data&features=hash_tag
#-2) http://www.mysite.com/index.php?dispatch=search_data&features=hash_tag

基本上,它们都是相同的,只是第一个网址中没有 index.php。

我得到以下代码以部分工作:

 RewriteCond %{QUERY_STRING} dispatch=(.*)
 RewriteRule ^$ http://www.mysite.com/? [L,R=301]

上面的代码适用于#-1(当没有index.php时),但是当有index.php时它不起作用。

非常感谢任何帮助/指导。

谢谢

____________ 更新____________ ___

根据请求,目标网址应如下: http://www.mysite.com/

I have this problem where I switched CMS from the old one to the new one so I am trying to redirect urls properly.

Here are some example urls I wanted to convert:

#-1) http://www.mysite.com/?dispatch=search_data&features=hash_tag
#-2) http://www.mysite.com/index.php?dispatch=search_data&features=hash_tag

Basically both of them are identical except the first one doesn't have index.php in the url.

I got the following to code to partially work:

 RewriteCond %{QUERY_STRING} dispatch=(.*)
 RewriteRule ^$ http://www.mysite.com/? [L,R=301]

The above code works for #-1 (when there is no index.php) but when there is index.php it doesn't work.

Any help / guidance is much appreciated.

Thanks

____________UPDATE_______________

As per request, here is what the the target url should be:
http://www.mysite.com/

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

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

发布评论

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

评论(3

一个人的旅程 2024-10-26 22:47:36

你说它“有效”是什么意思?

您可能应该发布一个示例,说明您希望新 url 在给定旧 url 的情况下是什么样子。

但无论如何,您的部分问题是 RewriteRule 行明确排除了 index.php 以及您网站上的任何其他页面。

你写的基本上可以翻译成这样:

if the query string contains "dispatch=...":
    redirect requests FOR THE HOME PAGE ONLY (^$) to http://www.mysite.com/

What do you mean it "works"?

You should probably post an example of what you want the new url to look like given the old url.

But in any case, part of your problem is that the RewriteRule line is specifically excluding index.php and any other page on your site.

What you wrote basically tranlates to this:

if the query string contains "dispatch=...":
    redirect requests FOR THE HOME PAGE ONLY (^$) to http://www.mysite.com/
潇烟暮雨 2024-10-26 22:47:36
RewriteCond %{QUERY_STRING} dispatch=(.*)
RewriteRule ^(index.php)?$ http://www.mysite.com/? [L,R=301]
RewriteCond %{QUERY_STRING} dispatch=(.*)
RewriteRule ^(index.php)?$ http://www.mysite.com/? [L,R=301]
帅气尐潴 2024-10-26 22:47:36

您是否尝试过更改第二部分以包含“index.php”部分?

RewriteRule ^$ http://www.mysite.com/index.php? [L,R=301]

have you tried changing the second part to include the "index.php" part?

RewriteRule ^$ http://www.mysite.com/index.php? [L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文