sKunKbad Posted May 1, 2009 Share Posted May 1, 2009 I'm trying out the kohana framework, and it routes or rewrites all traffic through index.php. This however isn't seen in the browsers address bar. I need to set up my .htaccess to convert non-www urls to www. This was easy in the past, but this framework has mixed things up a bit. Right now, I've got all pages except for the home page doing what it is supposed to. I'm just not sure how to tell apache to rewrite the url for the home page. This is what I have: RewriteRule .* index.php/$0 [PT,L] RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC] RewriteRule ^(index.php)?/(.*) http://www.mywebsite.com/$2 [R=301] So, any page other than the home page is converted to www. Quote Link to comment Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 1, 2009 Share Posted May 1, 2009 Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301] RewriteRule .* index.php/$0 [PT,L] </IfModule> You have to put the www rule before the other, because the [L] told to stop parsing the .htaccess and use this rule. You don't have to worry about the www rule with a [L] because the .htaccess will be called twice if the domain isn't www.mysite.com, it will be redirect using a 301 and reparsed with the new URL. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 1, 2009 Author Share Posted May 1, 2009 Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301] RewriteRule .* index.php/$0 [PT,L] </IfModule> You have to put the www rule before the other, because the [L] told to stop parsing the .htaccess and use this rule. You don't have to worry about the www rule with a [L] because the .htaccess will be called twice if the domain isn't www.mysite.com, it will be redirect using a 301 and reparsed with the new URL. I just get "Internal Server Error" when I try this Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 1, 2009 Author Share Posted May 1, 2009 Here is the whole doc if it matters # Turn on URL rewriting RewriteEngine On # Installation directory RewriteBase / # RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] # RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L, R=301] # Protect application and system files from being viewed RewriteRule ^(application|modules|system) - [F,L] # Allow any files or directories that exist to be displayed directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !^google2d216fed8ww53492f.html [NC] RewriteCond %{REQUEST_FILENAME} !^y_key_8b37d87ae82wwr07b3e.html [NC] RewriteCond %{REQUEST_FILENAME} !^robots.txt [NC] RewriteCond %{REQUEST_FILENAME} !^current-projects.php [NC] # Rewrite all other URLs to index.php/URL RewriteRule .* index.php/$0 [PT,L] redirect 301 /current-projects.php http://www.mysite.com/development.php the non-www to www is commented out because that gives me the error Quote Link to comment Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 1, 2009 Share Posted May 1, 2009 Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301] # RewriteRule .* index.php/$0 [PT,L] </IfModule> This work on my computer (i modify my host to be www.mysite.com=127.0.0.1) Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] # RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301] RewriteRule .* index.php/$0 [PT,L] </IfModule> This doesn't work. (500 internal error/too many redirects) I didn't read it i just assumed it work and put it after. [Fri May 01 14:51:26 2009] [error] [client 127.0.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary. Only this in a .htaccess crash here : Options +FollowSymLinks RewriteEngine On RewriteRule .* index.php/$0 [PT,L] I am assuming it has never work, the htaccess was getting a rule before it that was a match and stop parsing the .htaccess but i'm not sure. The last rules in the .htaccess "redirect 301 /current-projects.php http://www.mysite.com/development.php" will never be executed if you rewrite everything to index.php Quote Link to comment Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 1, 2009 Share Posted May 1, 2009 Forget about my last post Options +FollowSymLinks <IfModule mod_rewrite.c> # Turn on URL rewriting RewriteEngine On # Installation directory RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301] # Protect application and system files from being viewed RewriteRule ^(application|modules|system) - [F,L] # Allow any files or directories that exist to be displayed directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !^google2d216fed8ww53492f.html [NC] RewriteCond %{REQUEST_FILENAME} !^y_key_8b37d87ae82wwr07b3e.html [NC] RewriteCond %{REQUEST_FILENAME} !^robots.txt [NC] RewriteCond %{REQUEST_FILENAME} !^current-projects.php [NC] # Rewrite all other URLs to index.php/URL RewriteRule .* index.php/$0 [PT,L] Redirect 301 /current-projects.php http://www.mysite.com/development.php </IfModule> This work fine on my computer. I only remove some space, sometime i search too far and overcomplicated everything Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 1, 2009 Author Share Posted May 1, 2009 Thank you! That space was making me lose my hair! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.