views:

358

answers:

2

Hello , 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";

but it just shows my default controller

i also tried with htaccess

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]

it gives error for not having any passed data any help is appreciated. Cheers

+2  A: 

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:

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:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
naivists
yes it does work
Aviatrix
updated my post
naivists
now i get error 500 o.O
Aviatrix
See the Apache log files. Enable "RewriteLog" and see what's there (more info -http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteLog)
naivists
+1  A: 

i finally got it working >_>

routes file contains this

$route['([A-z0-9]{4})'] = "/forward/redirect/$1";

htaccess contains this

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]
Aviatrix