Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite url redirect problem
#1

[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]
#2

[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]
#3

[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!




Theme © iAndrew 2016 - Forum software by © MyBB