CodeIgniter Forums
mod_rewrite url redirect problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: mod_rewrite url redirect problem (/showthread.php?tid=3209)



mod_rewrite url redirect problem - El Forum - 09-17-2007

[eluser]freaksauce[/eluser]
I have the following set up to remove the index.php and its working fine:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|images|css|js|swfs|tmp)
RewriteRule ^(.*)$ /index.php/$1 [L]
However we now want to redirect 'http://www' to just 'http://' keeping any directories or pages in the url like this:
Code:
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
The only problem is that when it rewrites the url includes the '/index.php/' included (like this: http://mysite.com/index.php/category) which is messing up the clients tracking data. Is there a way of rewriting this in a different order?

The whole block is as follows:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|images|css|js|swfs|tmp)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]



mod_rewrite url redirect problem - El Forum - 09-17-2007

[eluser]alexsancho[/eluser]
Try this rules instead,

Code:
RewriteEngine On

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

    RewriteRule ^(.*)$ /index.php/$1 [L,QSA]



mod_rewrite url redirect problem - El Forum - 09-17-2007

[eluser]freaksauce[/eluser]
[quote author="alexsancho" date="1190030345"]Try this rules instead,

Code:
RewriteEngine On

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

    RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
[/quote]

Oh you are a legend, thanks so much I really don't understand mod_rewrite!