0

My htaccess right now:

# Use PHP 5.3
AddType application/x-httpd-php53 .php


RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

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

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php

I need to do a rule, that if somebody type http://www.mypage.com/blog/blablatitle

it redirects him to http://mypage.com/blog/blablatitle

and the same for the frontpage and all pages.

I am using CodeIgniter, but I think this is not so important when dealing with htaccess.

This suggested solution is not working well in CodeIgniter:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Because it adds index.php in the address e.g.: when I type:

http://www.mypage.com/blog/blablatitle

it redirects me to:

http://mypage.com/index.php?/blog/blablatitle

And I need:

http://mypage.com/blog/blablatitle

Without this rule it is ok (without index,php) e.g.: http://mypage.com/blog/blablatitle

So, any advice how to improve this redirect rule som index.php doesn't appear in the redirected link?

5
  • Believe your question is covered here stackoverflow.com/questions/234723/…
    – drk
    Dec 6, 2012 at 10:57
  • Thanks. I will try it. It is important to put it on the very first place (to the top above all)? Or it doesn's matter?
    – Derfder
    Dec 6, 2012 at 10:58
  • Ups, your link solution is not working. It adds index.php in the link when redirect in effect ;(
    – Derfder
    Dec 6, 2012 at 11:00
  • It has to be done slightly different for codeigniter I guess :(
    – Derfder
    Dec 6, 2012 at 11:00
  • SOLVED! ;) You need to put it right after RewriteEngine On RewriteBase /
    – Derfder
    Dec 6, 2012 at 11:15

2 Answers 2

1

SOLVED! ;) You need to put it right after

RewriteBase /
1

Try this please:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]

RewriteRule ^index.php(.*)$ http://%1/$1 [R=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.