• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with .htaccess


I wrote a CI app, and now it's time to make it work. The app is divided to controllers that have functions. Now if I want to access a controller's function I have to do this:
Now to make this google friendly I tried to write a .htaccess file, which rewrites the urls so that each function has a specific name that is translated. For example:
translates to:

but this wouldn't work. I tried to debug it by redirecting the url (using [R]), and that way it did work, but without that it doesn't.

Here's the .htaccess code:
RewriteEngine on
RewriteBase /

#if the url starts with /name1/...
RewriteCond $1 ^(name1)
#then replace it with /controller/function1/...
RewriteRule ^(name1)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ controller/function1

#if the url doesn't contain index.php, css, design, pics, robots.txt, license.txt at the beginning
RewriteCond $1 !^(index\.php|css|design|pics|robots\.txt|license\.txt)
#then precede the url (containing any character) with /index.php/
#this will be the last transform, as previously we made sure that the nice urls are understood
#RewriteRule ^(.*)$ /index.php/$1 [R,L]
RewriteRule ^(.*)$ /index.php/$1 [L]

what am I doing wrong?

[eluser]Adam Liszkai[/eluser]

My .htacess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]

And you can rename in /application/config/routes.php

$route['default_controller'] = "page";
$route['404_override'] = '';

$route['^(?!admin|login|download).*'] = "page/lang/$0";

Here when the url fisrt section is not admin or login or download then rewrite the code page/lang/ parameters...

And if you want it rename this shuld work(but im not test it):

$route['^(?name1).*'] = "name1/function/$0";

Cheers! Wink

Thanks Adam Liszkai,

I didn't know CI has a feature like this Smile
This gave me the idea to do things like this.
The suggested form of the regex didn't work, but after looking up this feature in the CI user guide, I came up with this:

$route['name1/(:any)'] = "controller/function1/$1";

works like charm Big Grin

[eluser]Adam Liszkai[/eluser]
Smile your wellcome

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.