0

Im developing a php frame work and I am new to .htaccess rules. So I need to redirect url using .htaccess. Url is

http://localhost/rinocabs/index.php?/Galary/Image/

should be converted to this

http://localhost/rinocabs/Galary/Image/

in .htaccess file I include these rules

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^localhost/rinocabs/index.php?/Galary/Image/ [nc]
rewriterule ^(.*)$ http://localhost/rinocabs/Galary/Image/$1 [r=301,nc]

but its not working. Please Help.

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Sajitha Rathnayake
  • 1,688
  • 3
  • 26
  • 47

4 Answers4

4
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

use this

localhost/rinocabs/index.php/Galary/Image/

instead of

localhost/rinocabs/index.php?/Galary/Image/

sas
  • 2,563
  • 1
  • 20
  • 28
  • Usefull. Actualy it is good. but don't help for my problem. Thanks – Sajitha Rathnayake Dec 20 '13 at 07:29
  • have you tried with `RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php? [NC]` – sas Dec 20 '13 at 07:41
  • I am interesting of your code. Im new to htaccess code. Could you please explain this code line by line. :) I got the result like this with this url localhost/rinocabs/index.php?/Galary/Image/ result is localhost/rinocabs/ – Sajitha Rathnayake Dec 20 '13 at 07:46
  • this will convert index.php from the url. you are not using any virtual host. you should try a local domain. that will fix your problem. – sas Dec 20 '13 at 07:59
  • no problem you can create domain in your localhost using virtual host as well – sas Dec 20 '13 at 08:24
0

When in doubt, go the Codeigniter route!

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

Basically there is no reason to include what's going to be the domain portion of your url in the rewrite rule and condition, and your condition is looking funky. Looking at the codeigniter example above, all we need to do in our expression is: find the index.php segment in the path, and get rid of it, and rewrite to include it. Your expression assumes the path will always be the same...if that makes sense.

Zarathuztra
  • 3,215
  • 1
  • 20
  • 34
0

Please try below code :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Kevin G Flynn
  • 231
  • 4
  • 14
0

Please try the following code. It's working properly.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Pang
  • 9,564
  • 146
  • 81
  • 122