[英]CodeIgniter Routing
I'm trying to build a short URI service with CI just so I can learn CI faster anyway .. I got stuck at the routing i hid the index.php then added the following route $route['([A-z0-9]{4})'] = "/forward/redirect/$1";
我正在尝试使用CI构建简短的URI服务,以便无论如何我都可以更快地学习CI。.我被路由卡住了,但隐藏了index.php,然后添加了以下路由
$route['([A-z0-9]{4})'] = "/forward/redirect/$1";
but it just shows my default controller 但这只是显示我的默认控制器
I also tried with HTaccess 我也尝试过HTaccess
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]
It gives an error for not having any passed data any help is appreciated. 由于没有任何传递的数据,因此提供任何帮助是错误的。 Cheers
干杯
Since there is no physical path /forward/redirect/
, you should redirect to the "catch all" index.php file in the root and input the path as parameter: 由于没有物理路径
/forward/redirect/
,因此您应该重定向到根目录中的“全部捕获” index.php文件,并将路径作为参数输入:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /index.php/forward/redirect/$1 [NC]
Or you can leave the rule as is and append another rule (this way you will have two rewriting cycles, the first one will rewrite to /forward/redirect/asdf
and then the second one rewrites to index.php/forward/redirect/asdf
: 或者,您可以按原样保留该规则并追加另一个规则(这样,您将有两个重写周期,第一个将重写为
/forward/redirect/asdf
,然后第二个重写为index.php/forward/redirect/asdf
:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
i finally got it working >_> 我终于让它工作了> _>
routes file contains this 路线文件包含此
$route['([A-z0-9]{4})'] = "/forward/redirect/$1";
htaccess contains this htaccess包含这个
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ index.php/forward/redirect/?$1 [NC]
RewriteCond $1 !^(index\.php|images|robots\.txt|(.*).js|(.*).css|(.*).jpg|(.*).png)
//added (.*) so resources could be loaded properly :)
RewriteRule ^(.*)$ /index.php/$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.