【问题标题】:How do you use .htaccess mod_rewrite to change the following您如何使用 .htaccess mod_rewrite 更改以下内容
【发布时间】:2016-03-28 10:27:13
【问题描述】:

如何使用 Mod_Rewrite 更改以下 URL?

main/order/$var to /$var

我已经在使用 .htaccess 将 /.index.php/$var 重写为 /$var。这是一个codeigniter设置。因此完整的 URL 将是 /.index.php/main/order/$var

这是我当前的文件:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|js|stats)
RewriteRule ^(.*)$ /index.php/main/order/$1 [L]

我在尝试对此进行调整时收到错误配置错误。

【问题讨论】:

  • 好吧,你为什么不简单地扩展现有的模式,因为你说它有效,你只想修改它。你已经知道怎么做了。
  • 如果您在此处确实有特定问题,请说出具体问题。请发布您现有的代码。
  • 添加了当前文件。很抱歉没有包括前期。谢谢
  • 抱歉,但这肯定不是 .htaccess 样式文件的工作版本。 RewriteCond $1 根本没有任何意义。 $1在这里要表达什么?

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

结果证明这是一个独特的 codeigniter 场景。我使用以下 .htaccess 进行了这项工作:

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots\.txt|css|js|stats)
RewriteRule ^(.*)$ /index.php/$1 [L]

然后我必须配置 routes.php 如下

$route['main'] = 'main/order';
$route['(:any)'] = 'main/order/$1';

【讨论】:

  • 我仍然无法理解 RewriteCond 但无论如何,如果它符合您的要求,那就太好了!
【解决方案2】:

我很困惑,您声称您发布了 .htaccess 样式文件的工作版本,但这看起来更像是您所做的尝试。 RewriteRule 中的 index.php 对我来说看起来很有趣(但我不太了解 codeigniter),它当然应该同时出现在RewriteCond 中em> RewriteRule...

你的RewriteRule 看起来不错,但我建议使用RewriteCond

RewriteEngine on
RewriteCond %{REQUEST_URI} !^(index\.php|images|robots\.txt|css|js|stats)
RewriteRule ^(.*)$ /index.php/main/order/$1 [L,QSA]

【讨论】:

  • 我在使用上述内容时收到 500 内部服务器错误。来自 apache 日志的错误:AH00124:由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用“LogLevel debug”获取回溯。
  • 对不起,我确实忘记了条件中的index.php 是防止这种重定向循环所必需的。现在应该可以工作了:-)
猜你喜欢
  • 1970-01-01
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-29
  • 1970-01-01
  • 2017-01-16
相关资源
最近更新 更多