【问题标题】:.htaccess multiple rewrite rules for codeigniter.htaccess 用于 codeigniter 的多个重写规则
【发布时间】:2012-09-05 09:47:57
【问题描述】:

我想问我们如何在 .htaccess 文件中添加额外的重写规则,包括 codeigniter 中的 index.php 删除规则。

这是我的 .htaccess 文件

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^profile/([0-9]+)$ /index.php/front/profileDetail/$1
RewriteRule ^(.*)$ /index.php/$1

问题是,一次只有一个规则有效。如果我如上所示保存文件,则会返回内部服务器错误!

我想要的是完全删除 index.php 文件,并将 xyz.com/front/profileDetail/50 中的 url 重写为 xyz.com/profile/50

请帮忙看看有什么问题,我在这方面完全是新手。

谢谢!提前。

【问题讨论】:

  • 我会使用路由 (config/routes.php) 将 xyz.com/front/profileDetail/50 重写为 xyz.com/profile/50,而不是 .htaccess。

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

要详细说明我上面的评论,请在 config/routes 中输入:

$route['profile/(:num)'] = 'front/profileDetail/$1';

【讨论】:

  • 谢谢!我认为您对使用 CI 路由重写 url 的建议比使用 .htaccess 更能被我接受。谢谢!又是很多。
  • @DipenGrg 很高兴能帮到你。请通过单击旁边的复选标记接受我的回答“已解决” - thx :)
猜你喜欢
  • 1970-01-01
  • 2015-02-15
  • 2017-11-21
  • 2013-06-29
  • 1970-01-01
  • 2015-02-15
  • 2019-01-17
  • 2013-02-14
相关资源
最近更新 更多