mod_rewrite 301从旧网址重定向到新codeigniter
我已经更新了我的网站,现在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
服务器不知道哪个 ID 可以与给定的标题匹配。您必须在 CodeIgniter 中处理这些情况。构建一个包含所有旧 ID 和新 URI 的表。编写一个脚本来处理这些请求并进行重定向。
示例(我最近没有接触过 CI):
.htaccess
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
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 aLocation
header.尝试使用
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.