RewriteRule 或 301 重定向

发布于 2025-01-02 20:54:10 字数 981 浏览 2 评论 0原文

我从我的朋友那里继承了一个用 ColdFusion 完成的网站。所有的网址都是这样的: index.cfm, filename.cfm?xid=MN

我做了这样的简单规则:

RewriteRule filename.cfm filename.php

它为顶级文件完成了工作。

但现在我正在处理二级文件,它们有这样的链接: filename.cfm?id=wanted&xid=MN 假设打开另一个页面,问题是当我写这个时:

RewriteRule filename.cfm?id=wanted&xid=MN folder/filename.php

它不起作用。我知道对于精明的开发人员来说这是一个愚蠢的问题,但我是新手,我需要帮助。请提出解决方案。非常感谢。

The pattern of those urls:
I have                                 I need
/fileone.cfm?id=overview&xid=MN        /folderone/overview.php
/fileone.cfm?id=wanted&xid=MN          /folderone/wanted.php
/fileone.cfm?id=services&xid=MN        /folderone/services.php


/filetwo.cfm?id=overview&xid=MN        /folderwto/overview.php
/filetwo.cfm?id=wanted&xid=MN          /folderwto/wanted.php
/filetwo.cfm?id=services&xid=MN        /folderwto/services.php

等等....

I have inherited a website from my friend which was done in ColdFusion. All urls are like:
index.cfm, filename.cfm?xid=MN

I did simple rules like this:

RewriteRule filename.cfm filename.php

and it did the work for top level files.

But now I'm working on second level files and they have links like this: filename.cfm?id=wanted&xid=MN wich suppose to open another page, the problem is when I write this:

RewriteRule filename.cfm?id=wanted&xid=MN folder/filename.php

it doesn't work. I know it's a stupid question for a savvy developer, but I'm a newbie and I need help. Please suggest a solution. This is very much appreciated.

The pattern of those urls:
I have                                 I need
/fileone.cfm?id=overview&xid=MN        /folderone/overview.php
/fileone.cfm?id=wanted&xid=MN          /folderone/wanted.php
/fileone.cfm?id=services&xid=MN        /folderone/services.php


/filetwo.cfm?id=overview&xid=MN        /folderwto/overview.php
/filetwo.cfm?id=wanted&xid=MN          /folderwto/wanted.php
/filetwo.cfm?id=services&xid=MN        /folderwto/services.php

And so on....

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

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

发布评论

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

评论(1

×眷恋的温暖 2025-01-09 20:54:10

将以下内容添加到站点根目录中的 .htaccess 文件中。

RewriteEngine on
RewriteBase / 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /file(one|two)\.cfm\?id=([^&]+)&xid=MN [NC]  
RewriteRule ^ /folder%1/%2.php? [L] 

这适用于您上面请求的所有重写,例如当用户请求 /fileone.cfm?id=overview&xid=MN 时,他们将获得 /folderone/overview.php< /代码>。

如果您想对用户进行 301 重定向,请将最后一条规则更改为

RewriteRule ^ /folder%1/%2.php? [L,R=301] 

Add the following to the .htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase / 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /file(one|two)\.cfm\?id=([^&]+)&xid=MN [NC]  
RewriteRule ^ /folder%1/%2.php? [L] 

This will work for all of the rewrites you requested above e.g. when the user asks for /fileone.cfm?id=overview&xid=MN, they will get /folderone/overview.php.

If you want to 301 redirect the users change the last rule to

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