繁体   English   中英

codeigniter .htaccess网址问题

[英]codeigniter .htaccess url issue

我想这样做:(首先,ci是我的codeigniter文件夹)
如果用户致电ci / 2012.htm,我想重定向ci / oyna / oyun / 2012.htm,我正在尝试使用它,但它没有运行。

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    RewriteRule ^(.*)$ index.php/oyna/oyun/$1 [L,QSA]

当我致电ci / 2012.htm时,它返回未找到codeigniter 404页面。

第一; 您有两个重写器,它们与您要进行的重写冲突;

RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(.*)$ index.php/oyna/oyun/$1 [L,QSA]

L标志表示如果某个规则匹配,则不会使用下一个规则。 由于2012.htm匹配第一个规则(两个规则都匹配所有规则),它将被重写为index.php/2012.htm并在那里停止,甚至没有进行oyna / oyun重写。

解决方案是交换规则,并使.htm重写更具体,以便仅重写.htm文件。 将规则更改为;

RewriteRule ^(.*\.htm)$ index.php/oyna/oyun/$1 [L,QSA]

应该更好地工作。

将最有选择性的规则放在第一位之后,结果应类似于(未经测试,此处没有Apache)

编辑:添加了缺少的RewriteCond,每个RewriteRule需要一个

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*\.htm)$ index.php/oyna/oyun/$1 [L,QSA]
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM