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?

kero
  • 10,647
  • 5
  • 41
  • 51
Derfder
  • 3,204
  • 11
  • 50
  • 85
  • Believe your question is covered here http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www – drk Dec 06 '12 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 06 '12 at 10:58
  • Ups, your link solution is not working. It adds index.php in the link when redirect in effect ;( – Derfder Dec 06 '12 at 11:00
  • It has to be done slightly different for codeigniter I guess :( – Derfder Dec 06 '12 at 11:00
  • SOLVED! ;) You need to put it right after RewriteEngine On RewriteBase / – Derfder Dec 06 '12 at 11:15

2 Answers2

1

SOLVED! ;) You need to put it right after

RewriteBase /
Derfder
  • 3,204
  • 11
  • 50
  • 85
1

Try this please:

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

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

drk
  • 865
  • 5
  • 9