mod_rewrite 301从旧网址重定向到新codeigniter

发布于 2024-09-28 06:42:02 字数 507 浏览 0 评论 0原文

我已经更新了我的网站,现在使用 codeigniter 框架 我的新网址如下 example.com/index.php/home/page/page-title

旧网址是 example.com/index.php?option=com_content&view =article&id=249

理想情况下,我想将所有以旧方式格式化的链接重定向到新链接,但网站上有很多页面,并且标题/id 不匹配。

我不想为每个页面编写单独的规则。例如

重定向 301 /oldpage.html http://www.example.com/newpage.html

我如果这样更容易的话,不介意将所有格式错误的网址重定向到主页/404 页面。

我可以看到这需要一个更复杂的规则,该规则使用我一直不太擅长的正则表达式。

任何帮助表示

感谢

I have updated my website to now use the codeigniter framework my new urls are like the following example.com/index.php/home/page/page-title

The old urls are example.com/index.php?option=com_content&view=article&id=249

Ideally I want to do a redirect for all links formatted in the old way to the new links but there are a lot of pages on the website and the titles/id do not match.

I do not want to write an individual rule for every page. eg

Redirect 301 /oldpage.html http://www.example.com/newpage.html

I do not mind having all the wrongly formated urls be redirected to the home page/404 page if this easier.

I can see this requires a more complicated rule that uses regex something I have never been very good at.

Any help appreciated

Thanks

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

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

发布评论

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

评论(2

单身情人 2024-10-05 06:42:02

服务器不知道哪个 ID 可以与给定的标题匹配。您必须在 CodeIgniter 中处理这些情况。构建一个包含所有旧 ID 和新 URI 的表。编写一个脚本来处理这些请求并进行重定向。

示例(我最近没有接触过 CI):

.htaccess

# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]

CodeIgniter

Redirector 可能是一个 CI 类,它查看 url验证 它为一个正整数,在数据库中搜索匹配的新 URI 并发送 Location 标头。

The server doesn't know which ID may match a given title. You will have to handle these cases in CodeIgniter. Build a table with all old IDs and new URIs. Write a script that handles these requests and does the redirect.

Example (I haven't touched CI recently):

.htaccess

# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]

CodeIgniter

Redirector could be a CI class, that looks into url, validates it as a positive integer, searches the database for a matching new URI and sends a Location header.

诺曦 2024-10-05 06:42:02

尝试使用 RewriteMap 指令。请参阅http://httpd.apache.org/docs/2.0/misc/rewriteguide。 html 了解详细信息。

Try the RewriteMap directive. See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文